copy image to "Application.StartupPath & "\saved

how to copy a image to "Application.StartupPath & "\

Page 1 of 1

8 Replies - 6491 Views - Last Post: 27 August 2009 - 07:59 AM Rate Topic: -----

#1 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

copy image to "Application.StartupPath & "\saved

Posted 23 August 2009 - 06:33 AM

hi. i need som help. i want to copy the chosen file to "Application.StartupPath & "\saved\" and then save tha path and file name. i know how to save it, but i dont know how o copy the file to that location.

here is the code for the "select image" button :
	 Dim OpenFileDialog1 As New OpenFileDialog
		OpenFileDialog1.ShowDialog()


		With OpenFileDialog1
			For Each s As String In OpenFileDialog1.FileNames
				.CheckFileExists = True

				.ShowReadOnly = False
				.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
				.FilterIndex = 2
				If .ShowDialog = DialogResult.OK Then
					Label13.Text = System.IO.Path.GetFullPath(s)

				End If
			Next
		End With



i use a hiden label to "show" the path. to the picturebox readīs the location from the label and the databas reads and writes the locatin to the label and the "openfiledialog" writes the location to the label. sp that simple. Anyone that can help me with th "copy file" part? :)

This post has been edited by EndLessMind: 23 August 2009 - 10:22 PM


Is This A Good Question/Topic? 0
  • +

Replies To: copy image to "Application.StartupPath & "\saved

#2 DataPriest  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 57
  • Joined: 29-April 09

Re: copy image to "Application.StartupPath & "\saved

Posted 24 August 2009 - 01:46 AM

There are many ways to kill a cat. To me, how to kill it matters most. I hope this is the best way to do it, not hidden controls and stuff, just code.

Try this code.

		Dim SAVE_PATH As String = Application.StartupPath & "\Saved"
		Dim FileDialog As New OpenFileDialog
		Dim fso = My.Computer.FileSystem

		With FileDialog
			If Not fso.DirectoryExists(SAVE_PATH) Then
				Try
					fso.CreateDirectory(SAVE_PATH)
				Catch ex As Exception
					MessageBox.Show("Unable to create folder '" & SAVE_PATH.ToLower & _
									"'.  Images will be saved in '" & Application.StartupPath.ToLower & _
									"'.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
					SAVE_PATH = Application.StartupPath
				End Try
			End If

			.InitialDirectory = SAVE_PATH
			.Filter = "All Graphic Files|*.bmp;*.gif;*.jpg;*.jpeg;*.png;|" & _
			"Graphic Interchange Format (*.gif)|*.gif|" & _
			"Portable Network Graphics (*.png)|*.png|" & _
			"JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg|" & _
			"Windows Bitmap (*.bmp)|*.bmp"
			.FilterIndex = 1
			.FileName = ""

			If .ShowDialog = Windows.Forms.DialogResult.OK Then
				If .FileName.ToUpper = (SAVE_PATH & "\" & fso.GetName(.FileName)).ToUpper Then
					MessageBox.Show("The file '" & fso.GetName(.FileName).ToLower & "' cannot be copied onto itself.", _
									Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
					Exit Sub
				ElseIf fso.FileExists(SAVE_PATH & "\" & fso.GetName(.FileName)) Then
					Dim Response As DialogResult

					Response = MessageBox.Show("The file '" & fso.GetName(.FileName).ToLower & "' already exist in the destination folder '" & _
											   SAVE_PATH & "'" & vbCrLf & vbCrLf & "Do you want to overwite it?", Text, MessageBoxButtons.YesNo, _
											   MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

					If Response = Windows.Forms.DialogResult.No Then Exit Sub
				End If

				Try
					fso.CopyFile(.FileName, SAVE_PATH & "\" & fso.GetName(.FileName), True)
				Catch ex As Exception
					MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
				End Try
			End If
		End With


This post has been edited by DataPriest: 24 August 2009 - 02:18 AM

Was This Post Helpful? 0
  • +
  • -

#3 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: copy image to "Application.StartupPath & "\saved

Posted 24 August 2009 - 09:38 AM

View PostDataPriest, on 24 Aug, 2009 - 12:46 AM, said:

There are many ways to kill a cat. To me, how to kill it matters most. I hope this is the best way to do it, not hidden controls and stuff, just code.

Try this code.

		Dim SAVE_PATH As String = Application.StartupPath & "\Saved"
		Dim FileDialog As New OpenFileDialog
		Dim fso = My.Computer.FileSystem

		With FileDialog
			If Not fso.DirectoryExists(SAVE_PATH) Then
				Try
					fso.CreateDirectory(SAVE_PATH)
				Catch ex As Exception
					MessageBox.Show("Unable to create folder '" & SAVE_PATH.ToLower & _
									"'.  Images will be saved in '" & Application.StartupPath.ToLower & _
									"'.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
					SAVE_PATH = Application.StartupPath
				End Try
			End If

			.InitialDirectory = SAVE_PATH
			.Filter = "All Graphic Files|*.bmp;*.gif;*.jpg;*.jpeg;*.png;|" & _
			"Graphic Interchange Format (*.gif)|*.gif|" & _
			"Portable Network Graphics (*.png)|*.png|" & _
			"JPEG File Interchange Format (*.jpg;*.jpeg)|*.jpg;*.jpeg|" & _
			"Windows Bitmap (*.bmp)|*.bmp"
			.FilterIndex = 1
			.FileName = ""

			If .ShowDialog = Windows.Forms.DialogResult.OK Then
				If .FileName.ToUpper = (SAVE_PATH & "\" & fso.GetName(.FileName)).ToUpper Then
					MessageBox.Show("The file '" & fso.GetName(.FileName).ToLower & "' cannot be copied onto itself.", _
									Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
					Exit Sub
				ElseIf fso.FileExists(SAVE_PATH & "\" & fso.GetName(.FileName)) Then
					Dim Response As DialogResult

					Response = MessageBox.Show("The file '" & fso.GetName(.FileName).ToLower & "' already exist in the destination folder '" & _
											   SAVE_PATH & "'" & vbCrLf & vbCrLf & "Do you want to overwite it?", Text, MessageBoxButtons.YesNo, _
											   MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

					If Response = Windows.Forms.DialogResult.No Then Exit Sub
				End If

				Try
					fso.CopyFile(.FileName, SAVE_PATH & "\" & fso.GetName(.FileName), True)
				Catch ex As Exception
					MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
				End Try
			End If
		End With


oh thanks :) but how do i add so the path it save in databas ( letīs name it "accounts" and the tablet "account info") and i want to save the path in colum "displypic".. how do i add the code? if i read the code you posted here right then it only open the dialog -> copy the file and then get the path, and you said the the best way is without hidden controls, so then i dont know how to do it.
( i hope you understand why i dont want to save the picture in the databas )

thanks in advance :)
Was This Post Helpful? 0
  • +
  • -

#4 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 670
  • Joined: 30-June 09

Re: copy image to "Application.StartupPath & "\saved

Posted 25 August 2009 - 02:52 PM

View PostEndLessMind, on 23 Aug, 2009 - 05:33 AM, said:

hi. i need som help. i want to copy the chosen file to "Application.StartupPath & "\saved\" and then save tha path and file name. i know how to save it, but i dont know how o copy the file to that location.

here is the code for the "select image" button :
	 Dim OpenFileDialog1 As New OpenFileDialog
		OpenFileDialog1.ShowDialog()


		With OpenFileDialog1
			For Each s As String In OpenFileDialog1.FileNames
				.CheckFileExists = True

				.ShowReadOnly = False
				.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
				.FilterIndex = 2
				If .ShowDialog = DialogResult.OK Then
					Label13.Text = System.IO.Path.GetFullPath(s)

				End If
			Next
		End With



i use a hiden label to "show" the path. to the picturebox readīs the location from the label and the databas reads and writes the locatin to the label and the "openfiledialog" writes the location to the label. sp that simple. Anyone that can help me with th "copy file" part? :)


However you do that, itll probably need admin privaleges
Was This Post Helpful? 0
  • +
  • -

#5 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: copy image to "Application.StartupPath & "\saved

Posted 25 August 2009 - 03:56 PM

Quote

However you do that, itll probably need admin privaleges

well yeah. the program allready do :P if i compile then i cant save anything to the databas with my program unless i run it as admin :P this is actually a V1.1 :P the first one was good. but back then i saved att pictures in the databas so the program was slow and tok more and more space on my harddrive for every person i added information about. and now iīve added the animation and removed the pictures from the databas so the program is like on drugs ^^ btw.. i havīnt solved it.. i just have my old solution with hidden labels that contains the path to the image. but i dont want it. so keep working ^^ becuase iīm going to speel now. school at 08.00 AM tomorrow. i be back at my computer by 08.30 PM.


( a other reason why iīm doing a V1.1 is becuase the program is going to be used as showing score in a game ( LAN-gaming) and stuff like that, and i first wroth this program on framework 4, and not many computer has that.. so iīm now writhing it on framework 2.)

This post has been edited by EndLessMind: 25 August 2009 - 04:14 PM

Was This Post Helpful? 0
  • +
  • -

#6 DataPriest  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 57
  • Joined: 29-April 09

Re: copy image to "Application.StartupPath & "\saved

Posted 26 August 2009 - 05:37 AM

Quote

oh thanks :) but how do i add so the path it save in databas ( letīs name it "accounts" and the tablet "account info") and i want to save the path in colum "displypic".. how do i add the code? if i read the code you posted here right then it only open the dialog -> copy the file and then get the path, and you said the the best way is without hidden controls, so then i dont know how to do it.
( i hope you understand why i dont want to save the picture in the databas )

thanks in advance :)


Hie EndLessMind;

Sorry for the late reply, I forgot to enable email notifications for this post. I just did that now.

Back to your query, do you have any code for this at the moment? If not, I need your connection string, table name and the fields to be affected.

This post has been edited by DataPriest: 26 August 2009 - 05:41 AM

Was This Post Helpful? 0
  • +
  • -

#7 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: copy image to "Application.StartupPath & "\saved

Posted 26 August 2009 - 09:03 AM

View PostDataPriest, on 26 Aug, 2009 - 04:37 AM, said:

Hie EndLessMind;

Sorry for the late reply, I forgot to enable email notifications for this post. I just did that now.

Back to your query, do you have any code for this at the moment? If not, I need your connection string, table name and the fields to be affected.


for the moment i have the code for the "openfiledialog" that you gave me, but i have add som code to it. Here is the code i added:
		Dim SAVE_filepath As String = Application.StartupPath & "\LANreg pic" & "\" & TextBox1.Text & ".jpg"
		Dim myImage As New Bitmap(SAVE_filepath )
		PictureBox2.Image = myImage
		Label13.Text = SAVE_filepath 


but iīm still using hidden controlls. The table name is "konto" the connection string is:
C:\Users\HåBe\Documents\Visual Studio 2008\Projects\Lanslaget project\Lanslaget project\konto.mdb

and the field is named "bild"

anything else? :)
Was This Post Helpful? 0
  • +
  • -

#8 DataPriest  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 57
  • Joined: 29-April 09

Re: copy image to "Application.StartupPath & "\saved

Posted 27 August 2009 - 04:03 AM

Hi EndLessMind;

I have written some code for you. Please go through it and I hope you will find what you need. I have written this code in a hurry but managed to test it. It's not perfect but it will shed some light.

The data source path is hard-coded, therefore you create the hard-coded path to place the sample database, or change the data source path to Application.StartupPath

The attached zip file contains the sample code, database and an image.

If you have any questions regarding the code, email me directly and I will be happy to answer your questions.

Regards;

PS Find my email address on line 3 of the Form1 code.

Attached File(s)


This post has been edited by DataPriest: 27 August 2009 - 04:06 AM

Was This Post Helpful? 0
  • +
  • -

#9 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,099
  • Joined: 13-March 09

Re: copy image to "Application.StartupPath & "\saved

Posted 27 August 2009 - 07:59 AM

View PostDataPriest, on 27 Aug, 2009 - 03:03 AM, said:

Hi EndLessMind;

I have written some code for you. Please go through it and I hope you will find what you need. I have written this code in a hurry but managed to test it. It's not perfect but it will shed some light.

The data source path is hard-coded, therefore you create the hard-coded path to place the sample database, or change the data source path to Application.StartupPath

The attached zip file contains the sample code, database and an image.

If you have any questions regarding the code, email me directly and I will be happy to answer your questions.

Regards;

PS Find my email address on line 3 of the Form1 code.

Thanks :) i will look in to it right away :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1