Throwing an exception when trying to attach a document to a list item
SharePoint
1
Posts
1
Posters
0
Views
1
Watching
-
I am throwing a System.ArgumentException () when trying to attach a document to a list item.
This is the code I am using. I had log statements in (since removed to cut down on extraneous code) that show me that I am getting up to the <pre>Item.Attachments.AddNow(FileName, binFile);</pre> statement when the exception is being thrown.
FileName is a String passed as a parameter to the web service.
Can anyone spot what I am doing wrong?
<pre lang="c#">
// open prototype site and web
site = new SPSite(SPContext.Current.Web.Url);
web = site.OpenWeb("cabinet");SPSite oSite = null; SPWeb oWeb = null; try { SPSecurity.RunWithElevatedPrivileges(delegate() { using (oSite = new SPSite(site.ID)) { using (oWeb = oSite.OpenWeb(web.ID)) { oWeb.AllowUnsafeUpdates = true; SPQuery query = new SPQuery(); query.Query = String.Concat( "<Where>", "<Eq>", "<FieldRef Name=\\"ItemNumber\\" />", "<Value Type=\\"Number\\">" + Id + "</Value>", "</Eq>", "</Where>"); query.ViewFields = String.Concat("<FieldRef Name=\\"ItemNumber\\" />"); query.RowLimit = 1; SPListItemCollection listItems = oWeb.Lists\["ListName"\].GetItems(query); // perform if item returned foreach (SPListItem Item in listItems) { try { String FilePath = String.Format("{0}{1}", Server.MapPath("~/\_doc\_