how to save spfile in physical location in c#

二次信任 提交于 2019-12-23 15:53:48

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/5230681/how-to-save-spfile-in-physical-location-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!