| |

VerySource

 Forgot password?
 Register
Search
View: 1438|Reply: 13

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

Post time: 2020-3-16 11:30:01
| Show all posts |Read mode
My database field "multiple attachment upload address" has the form:
A: / aaa; B: / bbb; C: / ccc;
What to do when downloading?

 public string FormatString (string str)
    {
        str = str.Replace ("", "" ";;
        str = str.Replace ("<", "<");
        str = str.Replace (">", ">");
        str = str.Replace ('\n'.ToString (), "<br>");
        return str;
    }
    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 ();

            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 ();
        }
    }

I can only download a single attachment in the form of: A: / aaa, how can I change it?
Thanks to the respondent ~~
Reply

Use magic Report

0

Threads

23

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-6-16 11:45:01
| Show all posts
A:/aaa;B:/bbb;C:/ccc
Cut into an array and make a loop
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-6-17 00:15:01
| Show all posts
You can list the files to be downloaded, and then the user chooses to download, or open a window for each attachment to download, but this seems to be a bad user experience
Reply

Use magic Report

2

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-6-17 21:00:01
| Show all posts
crabhero


   
For example: When I upload 3 files at a time, 3 rows of records are generated in the database:
A:/aaa;
A:/aaa;B:/bbb;
A:/aaa;B:/bbb;C:/ccc;
What I want is to generate only one row of records in the database for each upload, such as:
A:/aaa;B:/bbb;C:/ccc;
------------------------------------
The record you inserted into the database when you traversed to the last attachment is correct. Presumably you made the insertion inside the loop. In fact, you only need to construct the path string (A:/aaa;B:/bbb;C:/ccc; ) Insert just outside the loop, you can look at the code of your database operation

This is your answer to the "multiple attachment upload question" just now,
Thank you very much, now this download is difficult, please help me again
Reply

Use magic Report

0

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-6-18 09:45:01
| Show all posts
Define a string array, and then store the path into the array, such as:

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

Then use a loop output.
Reply

Use magic Report

0

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-6-18 22:30:01
| Show all posts
string path="A:/aaa;B:/bbb;C:/ccc";
string s=";"
char[] p=s.ToCharArray();
string b[]=path.Split(p);
for(int i=0;i<b.length;i++)
{
    Insert statement what insert into A values(b[i].Tostring());
}
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-6-19 01:15:01
| Show all posts
You can refer to the practice of most mail systems, when you receive an email with multiple attachments
The system creates a hyperlink for each attachment, and the user clicks to download the corresponding item instead of only providing a "download all" button
Download all attachments in one brain. An html page, only downloading a single file after specifying the contenttype. If you want to provide multiple attachments at once, you need to open multiple windows. It is not recommended to do this. If you need to do this, you can output the path combination to the page. Open a new window with javascript, and then pass the path to the new window one by one to download.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-6-19 13:45:01
| Show all posts
List the files to let the user choose, and it is not good to download all of them after clicking a link!
Otherwise, pack it all, and download the next compressed package afterwards!
Reply

Use magic Report

0

Threads

8

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-25 21:45:01
| Show all posts
string aaa = "A:/aaa;B:/bbb;C:/ccc";
Cut into an array and make a loop
string [] strAddress = aaa.slipt(";");
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-25 23:30:01
| Show all posts
Seriously agree with the method upstairs, requiring the length of the lower cut array, you can do a loop
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