Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

web.Folders[].Files.Add crashing with no error

$
0
0

Hi.

In the following code my intention is to upload a file programmatically from a folder on disk to a SharePoint 2010 document library. 

// Get the destination libraries                                    
                                    SPList destination = web.GetList(web.ServerRelativeUrl + sDocLib);
                                    // Get the root folder of the destination we'll use this to add the files
                                    SPFolder folder = web.GetFolder(destination.RootFolder.Url);
                                    web.AllowUnsafeUpdates = true;//SPFile curFile = web.Folders[sDocLib].Files.Add(sSourceFile, content);SPFile curFile = folder.Files.Add(web.Url + "/" + folder.Url + "/" + sSourceFile, content, true);
                                    web.Folders[sDocLib].Update();

But the code crashes on both the SPFile curFile = web.Folders line for both the commented out line of code and the uncommented line of code.

It crashes with no error when debugging.  I can upload to the document library manually.  I am running this directly on the server and debugging it in Visual Studio 2010.  This piece of code worked fine in SharePoint 2007.

Any ideas what the problem is?


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>