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
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