msdn上的示例 [Visual Basic, C#, C++] 下面的示例将文件从 http://www.contoso.com 下载到本地硬盘。 string remoteUri = "http://www.contoso.com/library/homepage/images/"; string fileName = "ms-banner.gif", myStringWebResource = null; // Create a new WebClient instance. WebClient myWebClient = new WebClient(); // Concatenate the domain with the Web resource filename. myStringWebResource = remoteUri + fileName; Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource); // Download the Web resource and save it into the current filesystem folder. myWebClient.DownloadFile(myStringWebResource,fileName); Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource); Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);
FileStream fs=new FileStream("F:\aa.txt",FileMode.OpenOrCreate);
byte[] file=new byte[fs.Length ];
fs.Write(file,0,fs.Length);
[Visual Basic, C#, C++] 下面的示例将文件从 http://www.contoso.com 下载到本地硬盘。
string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(myStringWebResource,fileName);
Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);
通过FileStream 读文件,直接返回给 客户端啊。
如何做?
对Web执行一个请求,获得返回响应的流HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/index.htm");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("GB2312")); string strPage = sr.ReadToEnd();
// 略
sr.Close();
response.Close();听海所说的就是 将流写入Response 的输出Stream
记得设置ContentType
其实我觉得filesrv就没必要再做成web方式
如果两台服务器在一起的话,直接以文件系统访问网络文件就可以了.何必还要再做成Web呢?
没办法,业务需要。我们有一个文件系统的产品,现在有一个web应用要调用文件系统的文档。但是文件系统和客户端是隔离的(如下图)A(web服务器)---------B(文件系统服务器)
|
|
|
客户端A与B交叉线相连,A与客户端在同一网段,文件系统B和客户端是隔离现在要在A上写程序以得到文件系统B的文件。