467,904 Members | 1,636 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,904 developers. It's quick & easy.

Going through a "File" input collection

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().ToLo wer();
int filePathLength = theFilePath.Length;
int lastBackslash = theFilePath.LastIndexOf(@"\");
string fileNameOnly =
theFilePath.Substring(lastBackslash+1,(filePathLen gth-(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
Nov 16 '05 #1
  • viewed: 1728
Share:
2 Replies
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
"news.bellatlantic.net" wrote:
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().ToLo wer();
int filePathLength = theFilePath.Length;
int lastBackslash = theFilePath.LastIndexOf(@"\");
string fileNameOnly =
theFilePath.Substring(lastBackslash+1,(filePathLen gth-(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

Nov 16 '05 #2
Thanks that did the trick!
"Ansil MCAD" <An*******@discussions.microsoft.com> wrote in message
news:25**********************************@microsof t.com...
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
"news.bellatlantic.net" wrote:
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().ToLo wer();
int filePathLength = theFilePath.Length;
int lastBackslash = theFilePath.LastIndexOf(@"\");
string fileNameOnly =
theFilePath.Substring(lastBackslash+1,(filePathLen gth-(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

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bhavin | last post: by
2 posts views Thread by @lias | last post: by
1 post views Thread by Jesper Hermansen | last post: by
4 posts views Thread by Petr Vileta | last post: by
7 posts views Thread by Tim Slattery | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.