Solution :
So i put a button called "Update" inside the A form. I also put two dropdown , and a text box to get 3 values ; title,column to update, update value .
Then i thought i can put some codes inside the button. Wow, this is just a piece of chocolate cake.
But just when i want to query the column of the doc library, i stuck. Dem!
ok i suppose i juz hardcoded it then
now...codes inside the button... unfortunately i'm not fluent in vb language. So let's do some translation. here are the code i want to manipulate :
Problem
You have a SharePoint list for which you want to update one or more of its items from within an InfoPath browser form.
Solution
Write code in an event handler for the InfoPath form that makes use of the SharePoint object model to update items in the SharePoint list.
Discussion
You can achieve this functionality as follows:
You should now have a fully functional form so that when you open the InfoPath form in a browser, change one or more titles for list items, and then click the Update Form button, all of the items you changed should get updated in the SharePoint list.
- In InfoPath, create a new Blank browser-compatible form template.
- Add a Data Connection to a SharePoint list. Here we'll use a SharePoint list called Fruits and select its ID and Title fields.
- On the Data Source task pane, select the secondary data source for the SharePoint list from the Data source drop-down list box.
- On the Data Source task pane, expand all of the nodes for the secondary data source, and then drag the repeating node for the SharePoint list to the InfoPath form template, drop it, and select Repeating Table from the context menu that appears.
- Add a Button control to the InfoPath form template.
- Double-click the button to open its Properties dialog box.
- On the Button Properties dialog box, select Update Form from the Action drop-down, and click OK.
- Right-click the field for the Title column in the Repeating Table for the secondary data source of the SharePoint list, select Programming, and then Changed Event from the context menu that appears.
- In the Project Explorer window in Microsoft Visual Studio Tools for Applications, right-click the node for the project name, and select Add Reference from the context menu.
- On the Add Reference dialog box, select Windows® SharePoint® Services from the list of components on the .NET tab, and click OK.
- In the FormCode.cs file, add a using statement for Microsoft.SharePoint.
- Add the following C# code to the Changed event handler for the Title field:
if (e.Operation == XmlOperation.ValueChange)
{
if (e.Site.Name == "Title" && e.OldValue != e.NewValue)
{
// Get the ID of the item to be changed
int id = Int32.Parse(e.Site.SelectSingleNode(
"../@ID", NamespaceManager).Value);
// Get the connection to the secondary data source SharePointListQueryConnection conn =
(SharePointListQueryConnection)DataSources["Fruits"]
.QueryConnection
Uri siteUri = conn.SiteUri;
// Update the SharePoint list item
using (SPSite site = new SPSite(siteUri.AbsoluteUri))
{
if (site != null)
{
using (SPWeb web = site.OpenWeb(siteUri.AbsolutePath))
{
SPList list = web.GetList(
siteUri.AbsolutePath + "Lists/Fruits");
if (list != null)
{
SPListItem item = list.GetItemById(id);
if (item != null)
{
item["Title"] = e.NewValue;
web.AllowUnsafeUpdates = true;
item.Update();
web.AllowUnsafeUpdates = false;
}
}
web.Close();
}
}
site.Close();
}
}
}
- Save your work and build the project.
- Give the InfoPath form template full trust.
- Publish the InfoPath form template to a SharePoint server running InfoPath Forms Services. Since the InfoPath form template contains code, you will have to perform an administrator-approved deployment.
ok let's try it!
UPDATE : Ok my head is about to crack crack crack crack.......>_<
ok..now... dear me, please refer to this :http://msdn.microsoft.com/en-us/library/gg435971.aspx
No comments:
Post a Comment