如何将文件从服务器复制到本地机器? [英] how to copy file from server to local machine?
问题描述
ı想要从服务器2008下载或复制任何类型的文件到本地机器ı编写此代码但不工作
string path = @ \\servername \\doc \\ ' + TextBox1.Text + '; textbox1.text包含文件名
string path2 = @ c:\ 跨度>;
System.IO.FileInfo fi1 = new System.IO.FileInfo(path);
fi1.CopyTo(path2);
非常重要的一点,服务器上有一个目录位置。
for ex <服务器c:/xxxx/xxxx/doc/xxx.txt或xxx.doc或xxx.pdf中的
想要说明所有用户都允许使用doc文件。
ı想要从这个位置下载或复制到本地机器c:/目录
为了将文件从服务器复制到本地机器,服务器必须共享相关的驱动器/文件夹(您可能必须配置权限才能访问共享)。如果您正在谈论通过网页下载,您需要配置IIS以允许下载文件类型(通过设置mime类型),然后设置响应
将文件返回给用户的对象。
亲爱的会员
不允许复制或写入任何文件到用户系统通过网络浏览器应用程序。
您的代码将考虑这行代码string path2 = @ c:\;
作为服务器的C盘而不是本地机器的C盘。
另外fi1.CopyTo(path2);将文件复制到服务器本身而不是用户机器(当IIS_WPG被授予必要的权限时也是如此)。 / blockquote>
此提问 - [复制文件来自服务器到本地计算机] [ ^ ]非常类似于你有一个经历线程。
ı want to do download or copy any type of file from server 2008 to local machine ı wrote this code but not work
string path = @"\\servername\\doc\\'"+TextBox1.Text+"'";textbox1.text include file name string path2 = @"c:\"; System.IO.FileInfo fi1 = new System.IO.FileInfo(path); fi1.CopyTo(path2);
very important point here there is a directory location on the server.
for ex
in the server c:/xxxx/xxxx/doc/xxx.txt or xxx.doc or xxx.pdf ı want to say that doc file allow for all users.
ı want to download or copy from this location to local machine c:/ directory解决方案In order to "copy" a file from a server to the local machine, the server has to share the drive/folder in question (and you will probably have to configure permissions in order to access the share). If you're talking about downloading via a web page, you need to configure IIS to allow the file type to be downloaded (by setting mime types), and then setting up aResponse
object to return the file to the user.
Dear member
It is not allowed to copy or write any file onto the users system via a web browser app.
Your code will consider this line of code "string path2 = @"c:\";
as the C drive of the server and not as the C drive of local machine.
Alsofi1.CopyTo(path2);will copy the file to server itself and not the users machine (and that too when the IIS_WPG has been granted the necessary permissions).
This question-[ Copy file from Server to local machine ][^] is very similar to your have a go through the thread.
这篇关于如何将文件从服务器复制到本地机器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!