Home > Net >  How to download the file to the local
How to download the file to the local

Time:05-13

I excel in the server folder down a excel file, and then I want to download to my local hard disk, but I used the following method to download is no problem, but D plate are downloaded to the server, rather than my local, how can I get to download to a local, I tried the following two methods are not
Method 1:
http://HttpWebRequest request=WebRequest. Create (" * * * * * * */Home/Excel/line data. XLSX ") as HttpWebRequest.
//send the request and obtain the corresponding response data
As HttpWebResponse HttpWebResponse response=request. The method GetResponse ();
//until the request. The method GetResponse () program to start sending a Post request to the target web page
Stream responseStream=response. GetResponseStream ();

//create a local file stream
Stream, Stream=new FileStream (" D: \ \ data. XLSX, FileMode. Create);

Byte [] bArr=new byte [1024].
Int size=responseStream. Read (bArr, 0, (int) bArr. Length);
While (size & gt; 0)
{
Stream. Write (bArr, 0, size);
Size=responseStream. Read (bArr, 0, (int) bArr. Length);
}
Stream. The Close ();
ResponseStream. Close ();

Method 2: WebClient client=new WebClient ();
Client. DownloadFile (" http://* * * * * */Home/Excel/line data. XLSX ", "D: \ \ data. XLSX");

CodePudding user response:

A novice? Stream, Stream=new FileStream (" D: \ \ data. XLSX, FileMode. Create);
Client. DownloadFile (" http://* * * * * */Home/Excel/line data. XLSX ", "D: \ \ data. XLSX");


This is not your own? D: specifies the line \ \ data. XLSX

CodePudding user response:

I just want to ask, you run this code in there

CodePudding user response:

references for 1/f, the emperor god reply:
novice? Stream, Stream=new FileStream (" D: \ \ data. XLSX, FileMode. Create);
Client. DownloadFile (" http://* * * * * */Home/Excel/line data. XLSX ", "D: \ \ data. XLSX");


This is not your own? D: specifies the line \ \ data. XLSX


Now is to download the server D dish, not my own computer D plate

CodePudding user response:

refer to the second floor wanghui0380 response:
I just want to ask, you run this code where

The code to run on the server, I want to achieve from the server to download an excel to my local computer d plate

CodePudding user response:

Server why access to your local computer, use the client download page download directly not good

CodePudding user response:

Read files into a stream object, and then receive stream object into a file, line, less complicated, with the object it

CodePudding user response:

You download, the server locally is not very normal

CodePudding user response:

If your method one and method two code running on your computer, it can be next to your computer, such as writing a winform procedure,,,

CodePudding user response:

Write winform

CodePudding user response:

 HttpWebRequest request=WebRequest. Create (" http://* * * * * * */Home/Excel/line data. XLSX ") as HttpWebRequest. 

To this address request resource
 Stream Stream=new FileStream (" D: \ \ data. XLSX, FileMode. Create); 

The response data, stored in the computer D plate of the program,

CodePudding user response:

WebClient wc=new WebClient ();
The string url="";
Wc. DownloadFile (url, "D: \ \ 123. XLSX");
The wc. The Dispose ();

You can I try the second method, what is the server configuration. Lead to download to come. You direct access to the resources on Internet explorer, and see if I can download

CodePudding user response:

reference wctmac123 reply: 3/f
Quote: refer to 1st floor eutopean royal god reply:
novice? Stream, Stream=new FileStream (" D: \ \ data. XLSX, FileMode. Create);
Client. DownloadFile (" http://* * * * * */Home/Excel/line data. XLSX ", "D: \ \ data. XLSX");


This is not your own? D: specifies the line \ \ data. XLSX


Now is to download the server D dish, not my own computer disk D



Eldest brother,,, you write is the server to download ah,,,

The server can access to your machine D offer?

Choose a drive to save time
  •  Tags:  
  • C#
  • Related