//fileUpload is ASP.Net FileUpload control.
if (!string.IsNullOrEmpty(fileQuotation.FileName))
{
using (SPSite site = new SPSite(sitename))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPDocumentLibrary docLib
= web.Lists[documentLibraryName] as SPDocumentLibrary;
//Get file extension ( *.doc OR *.docx )
string fileExtension
= fileQuotation.FileName.Substring(fileQuotation.FileName.IndexOf("."));
byte[] fileBytes = fileQuotation.FileBytes;
string destUrl
= docLib.RootFolder.Url + "/" + "MyFileName" + fileExtension;
SPFile destFile = docLib.RootFolder.Files.Add(destUrl, fileBytes, true);
SPListItem item = destFile.Item;
item["Title"] = "Title";
item.Update();
destFile.Update();
web.AllowUnsafeUpdates = true;
}
}
}
Monday, June 17, 2013
How do you upload a file to a document library in SharePoint?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment