naming image file you upload?

how to name image file you upload?

Page 1 of 1

6 Replies - 1412 Views - Last Post: 01 October 2009 - 05:51 AM Rate Topic: -----

#1 XMEGA   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 17-November 08

naming image file you upload?

Posted 29 September 2009 - 06:43 PM

How do you name the image file you upload using a textbox field?
I am able to upload an image to a folder but it uses the original name?

in this case if the textbox field is empty it uses the image filename...but I want it that if the user enters "Test" in the textbox field to name the image Test.jpg or something?
			If txtServerFileName.Text Is Nothing Or txtServerFileName.Text.Trim() = "" Then
				txtServerFileName.Text = txtfileUpload.FileName
			End If
			txtServerFileName.Text = txtServerFileName.Text.Trim

			Try
				Dim path As String = Server.MapPath("~/images")
				txtfileUpload.PostedFile.SaveAs(path & "\" & txtServerFileName.Text)

				lblMessage.Text = "Upload worked to :<br/>" & path & "\" & txtServerFileName.Text



Is This A Good Question/Topic? 0
  • +

Replies To: naming image file you upload?

#2 hackernewbie   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-September 09

Re: naming image file you upload?

Posted 30 September 2009 - 12:22 AM

View PostXMEGA, on 29 Sep, 2009 - 05:43 PM, said:

How do you name the image file you upload using a textbox field?
I am able to upload an image to a folder but it uses the original name?

in this case if the textbox field is empty it uses the image filename...but I want it that if the user enters "Test" in the textbox field to name the image Test.jpg or something?
			If txtServerFileName.Text Is Nothing Or txtServerFileName.Text.Trim() = "" Then
				txtServerFileName.Text = txtfileUpload.FileName
			End If
			txtServerFileName.Text = txtServerFileName.Text.Trim

			Try
				Dim path As String = Server.MapPath("~/images")
				txtfileUpload.PostedFile.SaveAs(path & "\" & txtServerFileName.Text)

				lblMessage.Text = "Upload worked to :<br/>" & path & "\" & txtServerFileName.Text



if(TextBox.Text.Trim().Length>0)
	Dim path As String = Server.MapPath("~/images")
				txtfileUpload.PostedFile.SaveAs(path & "\" & txtServerFileName.Text & TextBox.Text)


This post has been edited by hackernewbie: 30 September 2009 - 12:23 AM

Was This Post Helpful? 0
  • +
  • -

#3 XMEGA   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 17-November 08

Re: naming image file you upload?

Posted 30 September 2009 - 10:21 AM

View Posthackernewbie, on 29 Sep, 2009 - 11:22 PM, said:

View PostXMEGA, on 29 Sep, 2009 - 05:43 PM, said:

How do you name the image file you upload using a textbox field?
I am able to upload an image to a folder but it uses the original name?

in this case if the textbox field is empty it uses the image filename...but I want it that if the user enters "Test" in the textbox field to name the image Test.jpg or something?
			If txtServerFileName.Text Is Nothing Or txtServerFileName.Text.Trim() = "" Then
				txtServerFileName.Text = txtfileUpload.FileName
			End If
			txtServerFileName.Text = txtServerFileName.Text.Trim

			Try
				Dim path As String = Server.MapPath("~/images")
				txtfileUpload.PostedFile.SaveAs(path & "\" & txtServerFileName.Text)

				lblMessage.Text = "Upload worked to :<br/>" & path & "\" & txtServerFileName.Text



if(TextBox.Text.Trim().Length>0)
	Dim path As String = Server.MapPath("~/images")
				txtfileUpload.PostedFile.SaveAs(path & "\" & txtServerFileName.Text & TextBox.Text)


what is textbox.text? I used it as the textbox I want to name the image file I'm uploading but doesn't seem to work well...
Was This Post Helpful? 0
  • +
  • -

#4 XMEGA   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 17-November 08

Re: naming image file you upload?

Posted 30 September 2009 - 10:33 AM

I want to name the image file I am uploading
fileupload and a textbox is on my form with a button to upload...

I want to do this in theory however .Text does no work for fileupload/browse textbox
txtfileUpload.FileName.text = txtServerFileName.Text


Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: naming image file you upload?

Posted 30 September 2009 - 11:20 AM

try.

txtfileUpload.PostedFile.FileName = txtServerFileName.Text


Was This Post Helpful? 0
  • +
  • -

#6 XMEGA   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 135
  • Joined: 17-November 08

Re: naming image file you upload?

Posted 30 September 2009 - 03:37 PM

View Posteclipsed4utoo, on 30 Sep, 2009 - 10:20 AM, said:

try.

txtfileUpload.PostedFile.FileName = txtServerFileName.Text



doesn't like it says "FileName" is a read only property?
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: naming image file you upload?

Posted 01 October 2009 - 05:51 AM

you may not be able to change the file name.

If you've used AJAX before, they just released a new build. In this latest build, they added a new control to do asynchronous file uploads. You could take a look into that and see if it will allow you to change the file name.

wait....why don't you just use the textbox's text when you do the SaveAs?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1