Copying Files From SharePoint Location to Local Folder

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a VB 2010 Windows Form app that is intended to go to a specific SharePoint folder and copy the files from that folder to a folder on the local machine. I link to the SharePoint site using a UNC. For my testing I have mapped a drive to
the SharePoint location as well. What Im running into is that in order for my code to work I have to first go to the mapped drive, which will ask me to log on (SharePoint security I am assuming). After I do this my code runs just fine, doing what
I want. The issue is that ultimately this will be a scheduled task that will copy these files unattended. Ive seen references to the SharePoint SDK, do I need that, or is there some security setting that is missing that is not letting me access
the folder on SharePoint without having to first log in? Thanks.
Heres the specific code I have in place now:
<span style="color:blue; font-family:Consolas; font-size:9.5pt Dim<span style="font-family:Consolas; font-size:9.5pt FSO, SourceFolder, OrderFiles, SourcePath, DestinationPath

<p style="line-height:normal; margin-bottom:0pt <span style="color:blue; font-family:Consolas; font-size:9.5pt Dim<span style="font-family:Consolas; font-size:9.5pt sDateStamp
<span style="color:blue As <span style="color:blue String
<p style="line-height:normal; margin-bottom:0pt <span style="color:blue; font-family:Consolas; font-size:9.5pt Dim<span style="font-family:Consolas; font-size:9.5pt sFilesTrans
<span style="color:blue As <span style="color:blue String
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt sDateStamp = Format(Now(),
<span style="color:#a31515 "MMddyyHHmm")
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt sFilesTrans =
<span style="color:#a31515 ""
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="color:blue; font-family:Consolas; font-size:9.5pt On<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue Error <span style="color:blue GoTo err_Copy
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="color:green; font-family:Consolas; font-size:9.5pt Create scripting object to be used for copying
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt FSO = CreateObject(<span style="color:#a31515 "Scripting.FileSystemObject")
<p style="line-height:normal; margin-bottom:0pt <span style="color:green; font-family:Consolas; font-size:9.5pt Set Source Path

<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt SourcePath =
<span style="color:#a31515 "\intranet.mfri.comDavWWWRootCompaniesMidwescoFilterMetricsFilter Metric Documents"
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="color:green; font-family:Consolas; font-size:9.5pt Set Destination Path
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt DestinationPath =
<span style="color:#a31515 "C:TestingMetrics"
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="color:green; font-family:Consolas; font-size:9.5pt Set the folder in that we have to search the files
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt SourceFolder = FSO.GetFolder(SourcePath)
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="color:green; font-family:Consolas; font-size:9.5pt Get all the Files into the variable OrderFiles
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt OrderFiles = SourceFolder.Files
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt iFileCount = SourceFolder.Files.Count
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt progDownload.Maximum = iFileCount
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="color:blue; font-family:Consolas; font-size:9.5pt For<span style="font-family:Consolas; font-size:9.5pt
<span style="color:blue Each Orderfile <span style="color:blue In OrderFiles
<p style="line-height:normal; text-indent:0.5in; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt FSO.CopyFile(SourcePath &
<span style="color:#a31515 "" & Orderfile.Name, DestinationPath &
<span style="color:#a31515 "")
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
progDownload.Increment(1)
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
sFilesTrans = sFilesTrans & Orderfile.Name & vbCrLf
<p style="line-height:normal; margin-bottom:0pt <span style="color:blue; font-family:Consolas; font-size:9.5pt Next
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt

View the full article
 
Back
Top