SharePoint Developer Center >
SharePoint Products and Technologies Forums
>
SharePoint - Development and Programming
>
Upload a File into a DocLib and add metadata to it programatically
Upload a File into a DocLib and add metadata to it programatically
- Hello,
I want to upload files to document library and also add 5-6 metadata field to it programatically .What are the ways I can do it?
Are there any out of Box MOSS web service / Object model that will allow me to upload document as well as metadata?
Also, I need to get the Document library ID back as response.
Please suggest.
Answers
- You can use the copy web service (copy.asmx) to upload files to a document library and it will return you the url of the document. The same can be done with rpc. There is nothing out of the box that will return the document library id after uploading the document. However you can obtain the document library id from the returned url of the copy web service by using the SiteData web service's GetUrlSegments method. Below is some code to do this. It will also return the ListiItem id also.
http://sharepointfieldnotes.blogspot.com/2009/09/uploading-content-into-sharepoint-let.htmlpublic static string GetListItemIDByUrl(string url) { sitedataservice.SiteData sd = new sitedataservice.SiteData(); sd.Url = "http://basesmcdev2/sites/tester1/_vti_bin/sitedata.asmx"; sd.UseDefaultCredentials = true; string webId = string.Empty; string listId = string.Empty; string itemId = string.Empty; string bucketId = string.Empty; bool ret = sd.GetURLSegments(url, out webId, out bucketId, out listId, out itemId); return itemId; }
certdev.com- Marked As Answer byCharlie WuModeratorWednesday, November 11, 2009 2:10 AM
- The url is returned in the last argument to the CopyIntoItems method. This is an array of CopyResult objects and each has a Url property. If you read the blog link the only performance constraint is the fact that it is soap and the binary is base64 encoded which expands the payload of the request. Otherwise, we use it here and it works very well. RPC also works very fast and scalable.
certdev.com- Marked As Answer byCharlie WuModeratorWednesday, November 11, 2009 2:10 AM
All Replies
- You can use the copy web service (copy.asmx) to upload files to a document library and it will return you the url of the document. The same can be done with rpc. There is nothing out of the box that will return the document library id after uploading the document. However you can obtain the document library id from the returned url of the copy web service by using the SiteData web service's GetUrlSegments method. Below is some code to do this. It will also return the ListiItem id also.
http://sharepointfieldnotes.blogspot.com/2009/09/uploading-content-into-sharepoint-let.htmlpublic static string GetListItemIDByUrl(string url) { sitedataservice.SiteData sd = new sitedataservice.SiteData(); sd.Url = "http://basesmcdev2/sites/tester1/_vti_bin/sitedata.asmx"; sd.UseDefaultCredentials = true; string webId = string.Empty; string listId = string.Empty; string itemId = string.Empty; string bucketId = string.Empty; bool ret = sd.GetURLSegments(url, out webId, out bucketId, out listId, out itemId); return itemId; }
certdev.com- Marked As Answer byCharlie WuModeratorWednesday, November 11, 2009 2:10 AM
- Hello Steve,
Does the copy web service have any performance constraint?Also, How can get the URL or the ows_id field back after the upload is completed? - The url is returned in the last argument to the CopyIntoItems method. This is an array of CopyResult objects and each has a Url property. If you read the blog link the only performance constraint is the fact that it is soap and the binary is base64 encoded which expands the payload of the request. Otherwise, we use it here and it works very well. RPC also works very fast and scalable.
certdev.com- Marked As Answer byCharlie WuModeratorWednesday, November 11, 2009 2:10 AM


