Going through a "File" input collection

  • Thread starter news.bellatlantic.net
  • Start date
N

news.bellatlantic.net

I created a for with file inputs (<input type=file.../>) I named them file1,
file2, file3 etc. How do I access them in the code behind without actually
calling each one by name (there are 21 of them). This is what I have so far.
Strangely I get a error some of the time, I have not isolated it because I
can't get it to go to debug.

The code below kind of works about every 3rd one gives me an error and I
can't get it to go to debug! I get a "Cannot find server or DNS Error"
error, ugh!

// Home directory plus users directory
DirectoryInfo destDir = new DirectoryInfo(_destHomeDir + LabelGroup.Text +
"\\");

foreach(System.Web.UI.Control c in Page.Controls){
if(c is HtmlForm){
foreach(System.Web.UI.Control d in c.Controls){
if((d is HtmlInputFile)){
HtmlInputFile theFile = (HtmlInputFile)(d);
if(theFile.PostedFile!=null){
// The users file name including local path
string theFilePath =
theFile.PostedFile.FileName.ToString().Trim().ToLower();
int filePathLength = theFilePath.Length;
int lastBackslash = theFilePath.LastIndexOf(@"\");
string fileNameOnly =
theFilePath.Substring(lastBackslash+1,(filePathLength-(lastBackslash+1)));

// If the file name is not blank
if(theFilePath!=""){

// Make sure they are images or at least end with an image ext
"jpg", "gif"
if(IsPictureFileType(theFilePath)){

// Upload pictures to directory (full size)
File.Delete(destDir + fileNameOnly);
theFile.PostedFile.SaveAs(destDir + fileNameOnly);

// Save as thumbs
string thumbnailFileNameOnly =
fileNameOnly.Substring(0,(fileNameOnly.LastIndexOf(@"."))) + "_t" +
fileNameOnly.Substring(fileNameOnly.LastIndexOf(@"."),fileNameOnly.Length-fi
leNameOnly.LastIndexOf(@"."));

SaveAsThumbNail(destDir + fileNameOnly, destDir +
thumbnailFileNameOnly);
}
}
}
}
}

Anything you can offer would really be appreciated!

Thanks
 
G

Guest

hi
By default, ASP.NET only permits files that are 4,096 kilobytes (KB) (or 4
MB) or less to be uploaded to the Web server. To upload larger files, you
must change the maxRequestLength parameter of the <httpRuntime> section in
the Web.config file.

Note When the maxRequestLength attribute is set in the Machine.config file
and then a request is posted (for example, a file upload) that exceeds the
value of maxRequestLength, a custom error page cannot be displayed. Instead,
Microsoft Internet Explorer will display a "Cannot find server or DNS" error
message.

If you want to change this setting for all of the computer and not just this
ASP.NET application, you must modify the Machine.config file.

By default, the <httpRuntime> element is set to the following parameters in
the Machine.config file:

<httpRuntime
executionTimeout="90"
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

regards
Ansil
Trivandrum
 
N

news.bellatlantic.net

Thanks that did the trick!
Ansil MCAD said:
hi
By default, ASP.NET only permits files that are 4,096 kilobytes (KB) (or 4
MB) or less to be uploaded to the Web server. To upload larger files, you
must change the maxRequestLength parameter of the <httpRuntime> section in
the Web.config file.

Note When the maxRequestLength attribute is set in the Machine.config file
and then a request is posted (for example, a file upload) that exceeds the
value of maxRequestLength, a custom error page cannot be displayed. Instead,
Microsoft Internet Explorer will display a "Cannot find server or DNS" error
message.

If you want to change this setting for all of the computer and not just this
ASP.NET application, you must modify the Machine.config file.

By default, the <httpRuntime> element is set to the following parameters in
the Machine.config file:

<httpRuntime
executionTimeout="90"
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

regards
Ansil
Trivandrum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top