Code Operations SharePoint Document library (create, upload attachments)
Create Excel from an InfoPath form and upload it to a SharePoint-specific document library when you encounter customer needs in your project
Create a document library
SPSite site = new SPSite (SiteURL); SPListItem item = site. allwebs["website name"]. lists["list name"]. Folders.Add ("Document library URL", spfilesystemobjecttype.folder), item["Name"] = your Folder name;site. Rootweb.allowunsafeupdates = True;item. Update (); site. Rootweb.allowunsafeupdates = false;
Uploading files to a specified document library
FileStream fs = new FileStream (direct, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader (FS); byte[] FileContents = br. Readbytes ((int) fs. Length); Br. Close (); fs. Close (); SPFolder folder = Site. Rootweb.getfolder ("Document library URL"); string foldername = uploaded document Url;site. Rootweb.allowunsafeupdates = true;
SPFile sofle = folder. Files.add (foldername, filecontents, True);
Site. Rootweb.allowunsafeupdates = false;
Code Operations SharePoint Document library (create, upload attachments)