| |

VerySource

 Forgot password?
 Register
Search
Author: saxonn

Multi-attachment upload form, what should I do when downloading?

[Copy link]

2

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-7-10 01:15:01
| Show all posts
protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request["id"] != null)
        {
            int id = Convert.ToInt32(Request["id"]);//Convert to a number to prevent SQL injection

            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);
            conn.Open();
            adr = "select attachment upload address from Mail WHERE mail number = "+ id;
            SqlCommand cmd = new SqlCommand(adr, conn);
            string path = cmd.ExecuteScalar().ToString();
            //Get the path
            filepath = FormatString(path.ToString()).ToString().Trim();
            filepath = filepath.Substring(0, filepath.Length-1);//Remove the last semicolon
            string[] strpaths = filepath.Split(';');//Remove the path between semicolons and put them in the array

            for (int i = 0; i <strpaths.Length; i++)
            {
                string Temp_filename = FormatString(path.ToString()).ToString();
                int pos = Temp_filename.LastIndexOf("\\") + 1;
                filename = Temp_filename.Substring(pos, Temp_filename.Length-pos).ToString();
                filename = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(filename));

                Response.Clear();
                Response.ClearHeaders();
                Response.ClearContent();
                FileStream fs = new FileStream(filepath, FileMode.Open);
                long FileSize = fs.Length;
                byte[] Buffer = new byte[(int)FileSize];
                fs.Read(Buffer, 0, (int)fs.Length);
                fs.Close();
                Response.ContentType = "application/octe-stream";
                Response.AddHeader("content-disposition", "attachment;filename=" + filename);
                Response.Charset = "UTF-8";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.BinaryWrite(Buffer);
                conn.Close();
            }
        }
    }
Reply

Use magic Report

2

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-7-10 09:30:01
| Show all posts
The error is: The format of the given path is not supported.
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-11 12:45:01
| Show all posts
string aaa = "A:/aaa;B:/bbb;C:/ccc";
string [] strAddress = aaa.slipt(";");
foreach(string str in strAddress)
{
  this.response.write("<a href="+str+">"+str+"</a>");
}
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-11 13:15:01
| Show all posts
When storing to the database, you should store the relative address, of course, the absolute address is not supported by the web.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list