How to save spfile in physical location in C #

I need to save the spfile in a physical location. for drive: c.

I get the file using the following code:

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 the file in a physical location. enter the code.

+3
source share
1 answer

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 
  }
}

MSDN: SPFile.OpenBinaryStream

+6
source

All Articles