I am trying to download multiple files from a SharePoint site.
I have it working for one file, where I know the filename, by using a Script Task
WebClient client = new WebClient();
client.Credentials = GetCredentials();// Separate Method
client.DownloadFile(spFolderURL + "Filename.xlsx", spLocalFolder + "Filename.xlsx")
but I need to be able to loop through all the files within the folder and dynamically get the file name.
I am trying this code project solution and the solution below, I only need to download one file type (.xlsx).
using (SPSite oSite = new SPSite(spFolderURL))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList list = oWeb.Lists["listname"];
WebClient client = new WebClient();
SPListItemCollection oItemCol = list.GetItems();
foreach (SPListItem oItem in oItemCol)
{
string strID = Convert.ToString(oItem["ID"]);
SPFolder folder = oWeb.Folders["Lists"].SubFolders["Tasks"].SubFolders["Attachments"].SubFolders[strID];
foreach (SPFile file in folder.Files)
{
client.Credentials = GetCredentials();// Separate Method
client.DownloadFile(spFolderURL + "Filename.xlsx", spLocalFolder + "Filename.xlsx")
}
}
}
}
But I can't seem to get the SPSite and other SharePoint items recognised.
I have added a reference in the script to Microsoft.SharePoint.Client, but it looks like these items need Microsoft.SharePoint, I can't find that in the list of available assemblies.
I am using Visual Studio 2013
***EDIT
Have done further research I needed to download the SharePoint list adapters I am now able to access the SharePoint lists to extract the file names required.