Click here to Skip to main content
14,732,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have code that saves an image as a bitmap but uses the savefiledialog.
If I didn't want to use savefiledialog but just wanted to save the image to a specific folder in the application path how would I do that in vb net?

Well, let me explain it a bit more. I have a barcode image that is rendered and I need to save that as a bitmap without opening the savefiledialog.
This way the user can just scan the barcodes into the datagridviewer and then the image would be named the same as the barcode and saved to Barcodes folder in the applications path.

Hope this makes more sense.:confused:
Posted
Updated 2-Jun-10 7:18am
v2

That's really quite a simple thing to do.

Path.GetDirectoryName(Assembly.GetCallingAssembly.Location) gives you the folder that the program was started in.

Then, it's just a matter of adding the folder you want it put in and the file name you want it to be.

Let me show you an excerpt of some code I use in a program.

'Get the application path
Dim callingDir as String = Path.GetDirectoryName(Assembly.GetCallingAssembly.Location)

'See if the SpellCheck directory exists.  If not, create it.
If Not Directory.Exists(callingDir & "\SpellCheck") Then
  Directory.CreateDirectory(callingDir & "\SpellCheck")
  Dim newDirInfo as New DirectoryInfo(callingDir & "\SpellCheck")
  newDirInfo.Attributes = FileAttributes.Hidden
End If

'See if the AddedWords file exists.  If so, add the words to the dictionary.
If File.Exists(callingDir & "\SpellCheck\AddedWords.dat" Then
  'Do something with the file
End If
   
v2
Have a look at the Bitmap.Save[^] method.
   
Comments
William Winner 2-Jun-10 11:59am
   
His problem isn't with how to save it...SaveFileDialog doesn't actually save the file, all it does is get the path to save the file to.

I would assume he's already using Bitmap.Save or an equivalent method.
Kristian Sixhøj 2-Jun-10 12:05pm
   
I understood the question as he's opening a SaveFileDialog so the user can manually save it, but he wanted to save it without using/opening the SaveFileDialog. I may be wrong, but it's hard to tell without seeing the code.
William Winner 2-Jun-10 12:47pm
   
Do you actually understand what the SaveFileDialog does? It doesn't actually save anything to disk. I can write a program with a thousand SaveFileDialogs and without anything else, not a single file will be written to disk.

He wanted to know how to get the location that his application was being run from and how to get a file path without user input.
You can obtain the application's executable path with Application.ExecutablePath[^] and then call Bitmap.Save(string)[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900