Wednesday 19 February 2014

code for download notepad or txt file

--> if you want to download notepad file from the another website then
following code paste in your code behind file

-->Add namespace in your code behind file
-------------------------------------------------------------------------------------
    using System.IO;
    using System.Net;
    using System.Text;

-->next following code copy in your code behind file (.aspx.cs )
-------------------------------------------------------------------------------------
    WebClient client = new WebClient();
    string reply = client.DownloadString("path for you want to download file ");
    StringBuilder stringData = new StringBuilder();
    stringData.Append(reply);
    FileStream fs = new FileStream(@"Your path here :-where you store the file with file name", FileMode.Create);
    byte[] buffer = new byte[stringData.Length];
    for (int i = 0; i < stringData.Length; i++)
     {
         buffer[i] = (byte)stringData[i];
     }
    fs.Write(buffer,0, buffer.Length);
    fs.Close();

-->  above code use in your code behind on click event or
where you want to use

No comments:

Post a Comment



Asp.net tutorials