Reputation: 1639
i need to save the spfile in physical location. for ex: c drive.
i get the file using the code below:
using (SPSite site = new SPSite(item.Web.Site.ID))
{
using (SPWeb web = site.OpenWeb(item.Web.ServerRelativeUrl))
{
SPFile file = web.GetFile(item.File.UniqueId);
}
}
now how to save file in physical location. please give some code.
Upvotes: 3
Views: 4911
Reputation: 14880
Use SPFile.OpenBinaryStream()
to "open" the file:
SPFile file = ...;
using (Stream stream = file.OpenBinaryStream())
{
using (FileStream fs = File.OpenWrite("file path"))
{
// write file to the file stream here
}
}
Upvotes: 6