SharePoint 2013 Upload file to folder in document library -


i have following code places file in document library:

        public static void uploadfile(string siteurl, string libraryname, string file)     {         string filetoupload = file;         string sharepointsite = siteurl;         string documentlibraryname = libraryname;          using (spsite osite = new spsite(sharepointsite))         {             using (spweb oweb = osite.rootweb)             {                 if (!system.io.file.exists(filetoupload))                     throw new filenotfoundexception("file not found.", filetoupload);                  spfolder mylibrary = oweb.folders[documentlibraryname];                  // prepare upload                 boolean replaceexistingfiles = true;                 string filename = system.io.path.getfilename(filetoupload);                 filestream filestream = system.io.file.openread(filetoupload);                  // upload document                 spfile spfile = mylibrary.files.add(filename, filestream, replaceexistingfiles);                  // commit                 mylibrary.update();             }         }     } 

i want place file inside of folder in library called "nav" i'm not sure how make happen.. have tried cannot folder.

this latest effort:

spfolder mylibrary = oweb.folders[documentlibraryname].subfolders["nav"]; 

ideas?

this ended working me:

                spfolder mylibrary = oweb.folders[documentlibraryname];                 spfolder subfolder = mylibrary.subfolders["nav"]; 

seems messy works.. live.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -