Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

How can we save file from document library to local drive using code

  Asked By: Brianne    Date: Apr 18    Category: Sharepoint    Views: 4152

How can we save file from document library to local drive using code

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Rosalinda Merrill     Answered On: Apr 18

There are 2 easy ways:

1) WebDav - you can setup a network place and/or mapped drive  to the document
library and just use a batch script to do the copy.
2) Use an HTTP client of your choice to grab the file  using the URL

 
Answer #2    Answered By: Yogendra Zarapkar     Answered On: Apr 18

You can use this code


SPVirtualServer virtualServer = spGlobalAdmin.OpenVirtualServer(new
Uri(http://server-name));



SPSiteCollection collections = virtualServer.Sites;

SPSite site =collections[selValue];



foreach(SPWeb web in site.AllWebs)

{

if(web.Name =="reports")

{

SPWeb reportweb= site.AllWebs["reports"];



SPFolderCollection folders= reportweb.Folders;

foreach(SPFolder folder in folders)

{

#region

if(folder.Name == "Monthly Reports")

{

foreach(SPFolder subfolder in folder.SubFolders)

{

// for folder name pci for nov/dec

foreach(SPFolder childfolder in subfolder.SubFolders)

{

if(childfolder.Name== FolderList.SelectedItem.Value)

{

SPFile file  = childfolder.Files[ExcelList.SelectedItem.Value];

byte[] binFile = file.OpenBinary();

string path1 = @"c:\Reports.Xls";



// Delete the file if it exists.

if (File.Exists(path1))

{

File.Delete(path1);



}

// Create the file.

using (FileStream fs = File.Create(path1))

{

//Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the
file.");

// Add some information to the file.

fs.Write(binFile, 0, binFile.Length);

fs.Close();

}

break;

}

}

}

}

#endregion



}

 




Tagged: