I am trying to upload a lot of files to SharePoint programmatically using a windows forms application. I use the
SpFileCollection.Add() method to add the file and then attempt to set the properties by using that file's "Item" property. All the files are being loaded into the same folder of the same document library. My problem is, about 2600 files into this process (with 17,000 to go), it says "nope" because the Item property is
NULL. Why is it null, and how can I correct the issue and move on?
Looking at the source file it seems OK - I was able to view its properties in the CMS it started in and the file itself (a PDF) with no problems.
Hashtable htProperties = new Hashtable(); file = folder.Files.Add(contentsFromUCM.SharPointFilename, filecontent, htProperties, EnsureUser(ci.CreatedBy, web), EnsureUser(ci.ModifiedBy, web), ci.CreatedDate, ci.ModifiedDate, true); item = file.Item; // in debug mode the .Item is NULL item[SPBuiltInFieldId.Modified] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(ci.ModifiedDate.ToUniversalTime()); item[SPBuiltInFieldId.Editor] = EnsureUser(ci.ModifiedBy, web);
UPDATE: I learned to just ignore the problem. It only happens very rarely and with specific files so hopefully not enough of them come up where I can't just manually upload them later. I'll post a fuller answer if nobody has any better ideas.