Suresh Chaudhary
Suresh Chaudhary

Reputation: 1639

how to save spfile in physical location in c#

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

Answers (1)

Stefan
Stefan

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

MSDN: SPFile.OpenBinaryStream

Upvotes: 6

Related Questions