Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I specify the upload filename without an inputefile control

Status
Not open for further replies.

yongbum

Programmer
Dec 15, 2005
48
IL
Hi
How would I specify the file to upload to the server without an inputfile control on the form.
When the user clicks the uploadBtn I want to upload file 123.dat.
I'm using vb, code snipet appriciated.

Thanks
 
Sorry, code snippet is in C#; thats the language I speak...

Code:
// file name value of inputfile control 
string file = fileUploadTextBox.Value;

// get extension
string ext = file.Substring(file.IndexOf("."),file.Length-file.IndexOf("."));
		
// ad your new file name	
string filename = "MyCustomText" + ext;

// get the path to the file
string fullPath = System.Web.HttpContext.Current.Server.MapPath("C:\mydirectory" + filename)

// upload!
fileUploadTextBox.PostedFile.SaveAs(fullPath);

hope that helps.

-- shawn






</code>
 
Thanks shawn
Don't I have to declare the fileUploadTextBox to use its properties?
 
>>How would I specify the file to upload to the server without an inputfile control on the form.


not possible. as this will cause security concerns...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top