|Join Nairaland / LOGIN! / Trending / Recent / New|
Stats: 2,348,126 members, 5,208,481 topics. Date: Tuesday, 15 October 2019 at 02:38 AM
|C# - Capturing File Name From A FileUpload Control In Asp.net by csharpjava(m): 4:09pm On Jan 01, 2012|
Happy new year to all NL programmers.
I'm looking for a way to capture the file name from a FileUpload control, I can get the full path if I use TextBox1.CliectID in the code below. But how do I capture just the file name a CheckBoxList or similarl?
|Re: C# - Capturing File Name From A FileUpload Control In Asp.net by Gomez(m): 8:44pm On Jan 01, 2012|
This is one of code I wrote some years back, It gets the file name without extension first, then it gets the extension of the uploaded file too.
You can then work with the two strings the way that suites the application requirement
if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
string fn = Path.GetFileNameWithoutExtension(FileUpload1.FileName);
string extension = Path.GetExtension(FileUpload1.FileName);
You should look at the "Path" class, thats where your solution is.
|Re: C# - Capturing File Name From A FileUpload Control In Asp.net by csharpjava(m): 8:56pm On Jan 01, 2012|
Thanks for the code. I have tried it but it won't show the filename in a label when the user selects a file.
|Re: C# - Capturing File Name From A FileUpload Control In Asp.net by Gomez(m): 10:15am On Jan 02, 2012|
I assume this is your scenaro
1. when a user selects a file to upload, the file name of the selected file should show on a label somewhere in your page.
There is a jquery mulitple file upload plugin that can give you the information of the selected file.
You look at it so it will help.
|Re: C# - Capturing File Name From A FileUpload Control In Asp.net by Beaf: 10:26am On Jan 02, 2012|
|Re: C# - Capturing File Name From A FileUpload Control In Asp.net by csharpjava(m): 11:39am On Jan 02, 2012|
Thanks for the link I will try their sample code, which uses a CheckBoxList instead of a label this is even better as the user can delete a file from the list.
|Re: C# - Capturing File Name From A FileUpload Control In Asp.net by Kobojunkie: 8:24am On Jan 05, 2012|
A simple google search and woosh. , . . . google to the rescue
Seriously, in london and allergic to google
|Re: C# - Capturing File Name From A FileUpload Control In Asp.net by csharpjava(m): 9:34am On Jan 05, 2012|
Thanks for the link but thier solution does not solve it. Google is my best friend o, I always use it before coming to NL.
This link from a google search shows how to Post filename in a label from Fileupload control the innerHTML of the label is what is needed.
And with a few google search I was able to create this code to add only the the file name to a CheckBoxList. I have added the code below for anyone interested. The only problem is that you must manually create at least one Check Box Item first like this
<asp:listitem Value="1">Item 1</asp:listitem>before the script will work. Does anyone have a better way so as to avoid manually creating at least one Check Box Item first? or is AJAX the only solution?
|Re: C# - Capturing File Name From A FileUpload Control In Asp.net by taofeeq137(m): 11:16pm On Jul 04, 2015|
|Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health |
religion celebs tv-movies music-radio literature webmasters programming techmarket
Nairaland - Copyright © 2005 - 2019 Oluwaseun Osewa. All rights reserved. See How To Advertise. 42