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 (since removed to eliminate extraneous code) that showed me that I was getting to the
Item.Attachments.AddNow(FileName, binFile);
statement which was throwing the exception. The variable "FileName" is passed as a parameter of type String to the web service. The list has attachments enabled. Can anyone spot what I am doing wrong?
// open prototype site and web site = new SPSite(SPContext.Current.Web.Url); web = site.OpenWeb("cabinet"); SPSite oSite = null; SPWeb oWeb = null; if (0 < Id.Length && 0 < FileName.Length) { 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( "", "", "", "" + Id + "", "", ""); query.ViewFields = ""; 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\_uploads/"), FileName); FileStream fs = new FileStream(Fil