| |

VerySource

 Forgot password?
 Register
Search
View: 617|Reply: 6

How to find "upload control" only get the current user control instead of the entire page

[Copy link]

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-22 15:30:01
| Show all posts |Read mode
CS:
HttpFileCollection files = HttpContext.Current.Request.Files;
try
{
  for (int iFile = 0; iFile <files.Count; iFile ++)
  {
    HttpPostedFile postedFile = files [iFile];
    string fileName, fileExtension;
    fileName = System.IO.Path.GetFileName (postedFile.FileName);
    ...
  }
}
ASPS:
<INPUT id = "upfile" type = "file" name = "File" runat = "server">
This is the user control
But when I add multiple user controls to my page, the above code will also upload upload controls for other user controls.

How can i change
HttpFileCollection files = HttpContext.Current.Request.Files;
Cheng will only get the current user control instead of the "file" control for the entire page
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-7-1 13:30:01
| Show all posts
1. According to the control name, use FindControls to find.

2. Cycle through all the child controls according to the parent control. For example: put a Panel in the current user control and then cycle its child controls.

Request is the same object for the entire page, so Request.Files cannot be used directly
Reply

Use magic Report

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-2 02:30:01
| Show all posts
HttpContext.Current.Request.Files[this.upfile.ClientID];
Originally I thought the name in this collection would not work
Reply

Use magic Report

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-2 13:15:01
| Show all posts
(HttpFileCollection)this.FindControl("upfile");
This method of doing HttpFileCollection is not a server control
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-7-2 14:00:01
| Show all posts
You can also do this.


foreach(string sFileControl in Request.Files)
{
if(sFileControl.IndexOf(this.ClientID.ToString())>-1)
{
//Indicates that this control is its own.
}
}
Reply

Use magic Report

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-3 13:30:01
| Show all posts
HttpFileCollection files = HttpContext.Current.Request.Files;
try
{
for(int iFile = 0; iFile <files.Count; iFile++)
{
foreach(string sFileControl in files)
{
if(sFileControl.IndexOf(upfile.ClientID.ToString())>-1)
{
HttpPostedFile postedFile = files[iFile];
Will not work
Reply

Use magic Report

2

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-3 14:00:01
| Show all posts
HttpFileCollection files = HttpContext.Current.Request.Files;
try
{
  for(int iFile = 0; iFile <files.Count; iFile++)
  {
    foreach(string sFileControl in files)
    {
      if(sFileControl.IndexOf(upfile.ClientID.ToString())>-1)
      {
HttpPostedFile postedFile = files[iFile];
         ....
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