using (SPSite site = new SPSite("http://SiteURL"))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPFolder folder = web.Folders[site.URL + "/Shared Documents/"];
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPFolder folder = web.Folders[site.URL + "/Shared Documents/"];
byte[] content = null;
using (FileStream filestream = new FileStream(@"C:\MyDocument.docx",System.IO.FileMode.Open))
{
content = new byte[(int) filestream.Length];
filestream.Read(content, 0, (int) filestream.Length);
filestream.Close();
}
SPFile file = folder.Files.Add("MyDocument.docx", content, true);
}
}
using (FileStream filestream = new FileStream(@"C:\MyDocument.docx",System.IO.FileMode.Open))
{
content = new byte[(int) filestream.Length];
filestream.Read(content, 0, (int) filestream.Length);
filestream.Close();
}
SPFile file = folder.Files.Add("MyDocument.docx", content, true);
}
}
No comments:
Post a Comment