从远程服务器上载/下载文件 [英] File upload/ download from remote server

查看:142
本文介绍了从远程服务器上载/下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net Web应用程序.我正在尝试从远程服务器(在本地网络上)访问文件,但是很遗憾,它无法正常工作.问题是我不确定错误是否是cos所提及的路径不正确,或者这是iis7权限的问题.我在web.config文件中设置了< identity impersonate ="true"....以下是我尝试访问的代码:

Hi I have an asp.net web application. I am trying to access files from remote server (on local network) and unfortunately it isn’t working out. Problem is I am not sure if the error is cos the path mentioned isn’t correct or is this a problem with iis7 permissions. I have set <identity impersonate="true"... in web.config file. Below is the code i am trying to access :

Response.AppendHeader("content-disposition", "attachment; filename=" + 
 document.FileName);
 Response.ContentType = document.ContentType;
 String filepath = "\\<server-name>\<shared folder>\file.txt";
 Response.WriteFile(filepath);
 Response.End();



我尝试了文件路径字符串的所有可能组合.什么都行不通.请帮忙.



I have tried every possible combination of filepath string. Nothing works. Please help.

推荐答案

您是否尝试过使用具有正确凭据的用户从Windows资源管理器访问文件?另外,我看到的一个错误是您在字符串前面缺少了"@",否则,您需要用更多的转义符来限定转义符"\".
have you tried accessing the file from windows explorer with a user with the right credentials? Also, the one mistake I see is you''re missing the "@" preceding the string, otherwise, you need to qualify your escapes "\" with more escapes.


您好,我尝试过那:

Hi I tried that :

String filepath = @"\\<server-name>\\<shared folder>\\test.txt";



我得到了例外:

找不到文件




I get the exception:

"Could not find file


''\\\\<server-name>\\<shared folder>\\test.txt''



更新SM:当您输入@时,不要使用转义序列!请看书!
尝试:



UPDATE SM: When you put @, you don''t use escape sequences! Read books please!
try:

String filepath = @"\\<server-name>\<shared folder>\test.txt";


AFAIK,您无法从这样的网络访问文件.请阅读以下文章以了解详细信息.

如何使用asp.net访问网络文件 [
AFAIK you can''t access a file from network like that. Please read the following article for details.

How to Access Network Files using asp.net[^]


这篇关于从远程服务器上载/下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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