如何将文件从sharepoint中的文档库下载到本地文件夹? [英] How do you download a file from a document library in sharepoint to local folder?

查看:1930
本文介绍了如何将文件从sharepoint中的文档库下载到本地文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何将文件从sharepoint中的文件库下载到本地文件夹?我目前正在使用C#制作Windows应用程序,它将从文档库列表中下载文档。

我已经尝试过这段代码。但是我在使用(Stream destFile = System.IO.File.OpenWrite(destPath))此行时出现错误



  public   void 下载()
{
string destPath = @ c:/ Folder;
Sp.ClientContext spcontext = new ClientContext( HTTP:// Sharepointsite);
Directory.CreateDirectory(destPath);
使用(FileInformation ffl = Microsoft.SharePoint.Client.File.OpenBinaryDirect(spcontext, / Image))
{
使用(Stream destFile = System.IO .File.OpenWrite(destPath))
{
byte [] buffer = new byte [ 8 * 1024 ];
int len;
while ((len = ffl.Stream.Read(buffer, 0 ,buffer.Length ))> 0
{
destFile.Write(buffer,< span class =code-digit> 0
,len);
}
}
}
}

解决方案

1。请遵循Sandeep接受的回答 - 如何从中下载文件使用ssis的Sharepoint文档库? [ ^ ]。

另请参阅其他答案。



2. < a href =http://stackoverflow.com/a/726130>如何以编程方式从sharepoint站点下载文件? [ ^ ]。


 Microsoft SQL Server Integration Services脚本任务
'写使用Microsoft Visual Basic的脚本
'ScriptMain类是脚本任务的入口点。

Imports System.Net
Imports System.IO
Imports System
Imports System.Data
Imports System.Math
Imports System.Web
Imports System.Object
Imports System.Web.HttpResponse
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain

Public Sub Main()
'Dim strFileName As String = System.IO.Path.GetRandomFileName()
Dim URL As String = Dts.Variables(Url)。Value.ToString()
Dim strFriendlyName As String = Dts.Variables(Filename)。Value.ToString()'sample.txt

Dim dir As DirectoryInfo = New DirectoryInfo(Dts.Variables(ImportFolder))。 Value.ToString())

Dim credentials As System.Net.NetworkCredential = System.Net.CredentialCache.DefaultNetworkCredentials
Dim source As New Uri(https://testportal-ab.abc .net / deps / test / fold / destfold / sample.txt)
'Dim source1 As New Uri(URL& amp;/& amp; strFriendlyName &放大器;放大器; fileExtension)

Dim destination As String =C:\ Users \users1 \Desktop \destfold \& strFriendlyName
My.Computer.Network.DownloadFile(source,destination,credentials,True,60000I,False)
End Sub

End Class


hi,
How do you download a file from a document library in sharepoint to local folder? i am currently making a Windows application using C# that will download documents from a document library list.
i have tried this code. but i got error in
using (Stream destFile = System.IO.File.OpenWrite(destPath)) this line.

public void Download()
       {
           string destPath=@"c:/Folder";
           Sp.ClientContext spcontext = new ClientContext("http://Sharepointsite");
           Directory.CreateDirectory(destPath);
           using (FileInformation ffl = Microsoft.SharePoint.Client.File.OpenBinaryDirect(spcontext, "/Image"))
           {
               using (Stream destFile = System.IO.File.OpenWrite(destPath))
               {
                   byte[] buffer = new byte[8 * 1024];
                   int len;
                   while ((len = ffl.Stream.Read(buffer, 0, buffer.Length)) > 0)
                   {
                       destFile.Write(buffer, 0, len);
                   }
               }
           }
       }

解决方案

1. Follow this accepted answer by Sandeep - how to download files from Sharepoint document library using ssis?[^].
Also refer the other answer.

2. How do I programatically download a file from a sharepoint site?[^].


 Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.

Imports System.Net
Imports System.IO
Imports System
Imports System.Data
Imports System.Math
Imports System.Web
Imports System.Object
Imports System.Web.HttpResponse
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain

    Public Sub Main()
        ' Dim strFileName As String = System.IO.Path.GetRandomFileName()
        Dim URL As String = Dts.Variables("Url").Value.ToString()
        Dim strFriendlyName As String = Dts.Variables("Filename").Value.ToString() '"sample.txt"

        Dim dir As DirectoryInfo = New DirectoryInfo(Dts.Variables("ImportFolder").Value.ToString())

        Dim credentials As System.Net.NetworkCredential = System.Net.CredentialCache.DefaultNetworkCredentials
        Dim source As New Uri("https://testportal-ab.abc.net/deps/test/fold/destfold/sample.txt")
        ' Dim source1 As New Uri(URL &amp; "/" &amp; strFriendlyName &amp; fileExtension)

        Dim destination As String = "C:\Users\users1\Desktop\destfold\" & strFriendlyName
        My.Computer.Network.DownloadFile(source, destination, credentials, True, 60000I, False)
    End Sub

End Class


这篇关于如何将文件从sharepoint中的文档库下载到本地文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆