473,854 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Post edFile!=null){
// The users file name including local path
string theFilePath =
theFile.PostedF ile.FileName.To String().Trim() .ToLower();
int filePathLength = theFilePath.Len gth;
int lastBackslash = theFilePath.Las tIndexOf(@"\");
string fileNameOnly =
theFilePath.Sub string(lastBack slash+1,(filePa thLength-(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(IsPictureFil eType(theFilePa th)){

// Upload pictures to directory (full size)
File.Delete(des tDir + fileNameOnly);
theFile.PostedF ile.SaveAs(dest Dir + fileNameOnly);

// Save as thumbs
string thumbnailFileNa meOnly =
fileNameOnly.Su bstring(0,(file NameOnly.LastIn dexOf(@"."))) + "_t" +
fileNameOnly.Su bstring(fileNam eOnly.LastIndex Of(@"."),fileNa meOnly.Length-fi
leNameOnly.Last IndexOf(@"."));

SaveAsThumbNail (destDir + fileNameOnly, destDir +
thumbnailFileNa meOnly);
}
}
}
}
}

Anything you can offer would really be appreciated!

Thanks
Nov 16 '05 #1
2 2018
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 maxRequestLengt h parameter of the <httpRuntime> section in
the Web.config file.

Note When the maxRequestLengt h attribute is set in the Machine.config file
and then a request is posted (for example, a file upload) that exceeds the
value of maxRequestLengt h, 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
executionTimeou t="90"
maxRequestLengt h="4096"
useFullyQualifi edRedirectUrl=" false"
minFreeThreads= "8"
minLocalRequest FreeThreads="4"
appRequestQueue Limit="100"
/>

regards
Ansil
Trivandrum
"news.bellatlan tic.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.Post edFile!=null){
// The users file name including local path
string theFilePath =
theFile.PostedF ile.FileName.To String().Trim() .ToLower();
int filePathLength = theFilePath.Len gth;
int lastBackslash = theFilePath.Las tIndexOf(@"\");
string fileNameOnly =
theFilePath.Sub string(lastBack slash+1,(filePa thLength-(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(IsPictureFil eType(theFilePa th)){

// Upload pictures to directory (full size)
File.Delete(des tDir + fileNameOnly);
theFile.PostedF ile.SaveAs(dest Dir + fileNameOnly);

// Save as thumbs
string thumbnailFileNa meOnly =
fileNameOnly.Su bstring(0,(file NameOnly.LastIn dexOf(@"."))) + "_t" +
fileNameOnly.Su bstring(fileNam eOnly.LastIndex Of(@"."),fileNa meOnly.Length-fi
leNameOnly.Last IndexOf(@"."));

SaveAsThumbNail (destDir + fileNameOnly, destDir +
thumbnailFileNa meOnly);
}
}
}
}
}

Anything you can offer would really be appreciated!

Thanks

Nov 16 '05 #2
Thanks that did the trick!
"Ansil MCAD" <An*******@disc ussions.microso ft.com> wrote in message
news:25******** *************** ***********@mic rosoft.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 maxRequestLengt h parameter of the <httpRuntime> section in
the Web.config file.

Note When the maxRequestLengt h attribute is set in the Machine.config file
and then a request is posted (for example, a file upload) that exceeds the
value of maxRequestLengt h, 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
executionTimeou t="90"
maxRequestLengt h="4096"
useFullyQualifi edRedirectUrl=" false"
minFreeThreads= "8"
minLocalRequest FreeThreads="4"
appRequestQueue Limit="100"
/>

regards
Ansil
Trivandrum
"news.bellatlan tic.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.Post edFile!=null){
// The users file name including local path
string theFilePath =
theFile.PostedF ile.FileName.To String().Trim() .ToLower();
int filePathLength = theFilePath.Len gth;
int lastBackslash = theFilePath.Las tIndexOf(@"\");
string fileNameOnly =
theFilePath.Sub string(lastBack slash+1,(filePa thLength-(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(IsPictureFil eType(theFilePa th)){

// Upload pictures to directory (full size)
File.Delete(des tDir + fileNameOnly);
theFile.PostedF ile.SaveAs(dest Dir + fileNameOnly);

// Save as thumbs
string thumbnailFileNa meOnly =
fileNameOnly.Su bstring(0,(file NameOnly.LastIn dexOf(@"."))) + "_t" +
fileNameOnly.Su bstring(fileNam eOnly.LastIndex Of(@"."),fileNa meOnly.Length-fi leNameOnly.Last IndexOf(@"."));

SaveAsThumbNail (destDir + fileNameOnly, destDir +
thumbnailFileNa meOnly);
}
}
}
}
}

Anything you can offer would really be appreciated!

Thanks

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7521
by: Bhavin | last post by:
Hi I'm trying to set default value for input type file. <input type="File" name="tx_pdffile" accept="*.pdf" class="boxText" value="abc.pdf"> but this value (abc.pdf) doesnt appear in the text box.. Whats the solution???
2
44034
by: @lias | last post by:
Hi all I have a webpage where I want the user to input filenames. To make this easier, I use a file input type so that the user can select files rather than typing in the filename, using the HTML below. <input type="file" size="25" maxlength="256" id="filename" onchange="AddFile()" /> The problem I have is that the javascript function AddFile() is only run under
1
27915
by: Jesper Hermansen | last post by:
Hi! I'm making a system that will generate Winamp-playlists. To make it easy for the user to add a file to the list, I'm using <input type="file">. The problem with this is that I only get the filename, not the path, which is necessary in my situation. I cracked the problem in Firefox:
2
28587
by: Matt | last post by:
If I do the following, the browse text box still cannot see C:/hello world/test.txt. <input type="file" name="fileName" value="C:/hello world/test.txt" size=80> Any ideas? and workarounds to this problem? thanks!!
4
9268
by: acord | last post by:
Hi, I want to change the name of Browse to Add... How can I modify the followoing html code? <form name="iform" action="" method="post" enctype="multipart/form-data"> <input id="file" type="file" name="image" onchange="upload()" /> <input type="hidden" name="imgnum" />
4
7864
by: Petr Vileta | last post by:
Sorry if my question was be here earlier, I'm new here ;-) I have html form where is the tag <input id="x" type="file" name="upload"> and another fields. After submit script on server take some validation on some fields and if te error is found the same form is generated with error reporting message. But the content of the "file" input is lost. I test it in IE6 and parameter value="???" not work here. I try to put string into input...
9
24757
by: Prakash Singh Bhakuni | last post by:
am replacing the default "Browse..." button for input type=file. This works fine except that the form will only submit after the SUBMIT button is clicked twice. Any ideas on why this is happening or a workaround? I'm testing on IE Thanks! <html> <head></head> <body> <form name="test_form" method="post" action="test.jsp">
7
20877
by: Tim Slattery | last post by:
I'm trying to handle the onChange event in an <input type="file"> element. In IE, there's no problem: the event fires when a file in the "open" box is doubleclicked, or the "Open" button in the box is clicked, or "Enter" is hit in the attached text box. I can get the value of the element. But in Netscape 7, onChange doesn't fire until focus leaves the element. When you double-click a file name or click "open" in the Open box, the...
5
34025
by: cssExp | last post by:
alright suppose i have the following. <input type="file" name="upload" /> <input type="text" name="discription" /> <input type="image" onclick="addFile();" src="images/addfile.jpg" name="add" alt="Add file" /> Here when user clicks add button, it gets added dynamically in to a div. Which all good and nice, i have very well done so. But here is the problem, on that parent div there are children, children divs contains the input which...
1
14043
by: ChollaPete | last post by:
This code: <form action="processScan.php" method="get"> <p> <?php print "Scan name: <input type=\"file\" name=\"tScanFileName\" value= \"{$scanFileName}\"><br>"; addHiddenCarryons(); ?> <input type="submit">
0
10672
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10740
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9509
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5936
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4147
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.