How to download files in third party Girdview, and JS display pictures

Source: Internet
Author: User

<summary>

File Download Events

</summary>

<param name= "Sender" ></param>

<param name= "E" ></param>

protected void Grid_oncopyinsertclick (object sender, EventArgs e) {

LinkButton lbut = sender as LinkButton;

string Sellcontractscanid = Lbut.commandname;

String url = "";

String name = "";

foreach (DataRow dr in Griviewtable.rows) {

if (dr["ordinal"]. ToString (). Equals (Sellcontractscanid)) {

url = dr["path"]. ToString ();

Name = dr["file name"]. ToString ();

Break

}             }

if (System.IO.File.Exists (HttpContext.Current.Server.MapPath (URL))) {

Response.Redirect ("Userinfoscandownload.aspx? Filepath= "+ URL +" &filename= "+ name);

}

Else

{BP. Alert ("The file does not exist!") ");

}

BasePage BP = null;

protected void Page_Load (object sender, EventArgs e) {

if (request["FilePath"] = = null)

Return

if (request["FileName"] = = null)

Return

String filerpath = request["FilePath"]. ToString ();

string filename = request["filename"]. ToString ();

if (System.IO.File.Exists (HttpContext.Current.Server.MapPath (Filerpath))) {

Response.ClearHeaders ();

Response.Clear ();

Response.Expires = 0;

Response.Buffer = true;

Response.AddHeader ("Accept-language", "ZH-TW");

String name = System.IO.Path.GetFileName (Filerpath);

System.IO.FileStream files = new FileStream (HttpContext.Current.Server.MapPath (Filerpath), FileMode.Open,                 FileAccess.Read, FileShare.Read); byte[] bytefile = null;

if (Files. Length = = 0) {

Bytefile = new Byte[1];

}

Else

{

Bytefile = new Byte[files. Length];

}

Files. Read (bytefile, 0, (int) bytefile.length);

Files. Close ();

Response.AddHeader ("Content-disposition", "attachment;filename=" + httputility.urlencode (filename,                 SYSTEM.TEXT.ENCODING.UTF8)); Response.ContentType = "APPLICATION/OCTET-STREAM;CHARSET=GBK";

Response.BinaryWrite (Bytefile);

Response.End ();

}

}

How to download files in third party Girdview, and JS display pictures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.