简体   繁体   中英

Downloading FIles on Asp.net

this is my code

protected void btnUpload_Click(object sender, EventArgs e)
{
    try
    {
        string filename = Path.GetFileName(FileUpload1.FileName);
        FileUpload1.SaveAs(Server.MapPath("~/CustomerFiles/") + filename);
        lblResult.Text = "Your File " + filename + " is Succesfull uploaded!";
        //lblFile.Text = FileUpload1.FileName;
        lblFile.Text = "../CustomerFiles/" + filename;
        Page_Load(sender, e);
    }

    catch (Exception)

    {
        lblResult.Text = "Upload Failed";
    }
}

I can Upload files but I can't see it in my visual studio 2013.I need to see my uploaded files in order for me to download it and save its filepath to Sql Database.

This my code to download the file

protected void Button1_Click(object sender, EventArgs e)
    {
        string filename = "~/Files/Mastering MeteorJS Application Development.pdf";
        String _fileName = "akash";
        string path = MapPath(filename);
        //byte[] bts = System.IO.File.ReadAllBytes(path);
        Response.Buffer = true;
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition:", "attachment;filename=" + _fileName + ".pdf");
        Response.TransmitFile(path);
        //Response.Close();
    }

There is a problem i faced when published the web application.This Files folder does not copy on Published folder on visual studio 2010 after publishing the app to file system.so i manually copy the Files directory with contents after published of web application and paste in that dir. now its ok

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM