Create Folder and save file through fileopenDialog - vb.net

i am using FileOpenDialog control to save file in C: drive,
Now i want to create New Folder and save the file in that folder with FileOpenDialog.
and also from other forms i have to store different file in that same foldr.
Please any one suggest me.

i think this link may help you
http://social.msdn.microsoft.com/Forums/vstudio/en-US/9bc2c92a-b22f-484c-9a15-0aebf639422d/folder-browser-dialog-in-vbnet-2010
by the way you should use SavefFileDialog or FolderBrowserDialog

First of all, you should use the SaveFileDialog to save the file. Not the file open dialog. The SaveFileDialog control will automatically let the user also create a folder -- just open the dialog in run-time mode and right click inside and see.. New > New Folder. Once the user navigates into this newly created folder and specifies the file name, all you need to do is to save the file.
Alternately, if you want to use a fixed subfolder, don't prompt the user to create the folder for you. Instead after the dialog is dismissed, do this --
string savePath = saveFileDialog1.FileName;
string directory = System.IO.Path.GetDirectoryName(savePath);
savePath = string.Format(
"{0}\\MySubFolder\\{1}",
directory,
System.IO.Path.GetFileName(savePath)
);
Save the file to the path in "savePath".
(PS: Sorry my above snippet is in C#, but you should be able to easily convert it to VB.NET).

Related

Create Document in the Folder the EXE is in (VB)

I'm starting to play around with FileStream to make a text document. When you do this, you have to clarify a path. Is there a way to create the text document in the folder the EXE file is in?
(I'm asking this because this program is meant to be downloaded, so I think I can't clarify a path specific to my computer)
Thank you!
You're right, you can't bake a path into your program that is specific to your computer because then it won't work on the user's computer
Jimi makes the wise point that often programs are installed to C:\Program Files or similar and it's not automatically possible to write to subfolders in there - you'll have to get into asking the user for permission (Elevation) .. headache
Better to decide what you want the path for:
If you need a temporary path to e.g. download something to then throw it away you can call Path.GetTempFilename() or Path.GetTempPath() - the former creates a 0 byte file with a random name in the user's temp folder, and returns the path. The latter gives you the path to the temp folder so you can create your own file
If the file is to have some permanence, such as the user saving his work, you should ask the user for it. SaveFileDialog and FolderBrowserDialog are two things you can drop on your windows form and then call ShowDialog() on to show the uer a UI where they pick a path. After they OK or Cancel, you check if they OK'd or Cancel and proceed using the dialog's Filename or SelectedPath respectively (if they OK'd)
When you're writing your files it's easier not to use FileStream unless you really need to seek in the file etc. Easier to just:
System.IO.File.WriteAllText(path here, contents here)
If you have to write the contents of a string variable to a file
The best way to create a text file, would be to use CreateText method. It will create a file besides the executable program file. You can go the following way.
Dim sw as StreamWriter = File.CreateText("myfile.txt")
Dim str as String = "Your text"
sw.Write(str)
sw.Flush()
sw.Close()

Print button didn't save the PDF file at a shared path, and no error logged

I have an Excel macro that uses SAP for printing data in pdf format.
Steps:
it access the SAP transaction which provides a table with the necessary information
it press Print button (from the Menu Bar of SAP)
then Print window appears (from here it is selected Microsoft Print To PDF option and then it is pressed OK button)
Save As window appears (complete the path and filename: \S\BC....\outputName)
then Save button it is pressed
then no error happens
But if I access the path folder "\S\BC....", nothing happen, there is no file saved. BUT, if we look in "Date modified" property of the folder, it is modified in accordance with the last saving time.
Also, I mention that if I'm trying to write the pdf file on local folders, not network shared folders (example: a desktop folder: C:\Users\mariah\Test), macro works.
Also, I mention that user can Read&Write at the shared path \S\BC....\
Please help me to find the cause of this issue.
A VBA macro only does what you are allowed to do manually. Can you manually save the file in the shared path without the macro?
Is the common path really \S\BC...\ or \ \S\BC...\ ?
Regards,
ScriptMan
Solution proposed by the OP in this comment:
IT WORKS if I save the file on "C:\Users\UserName" and then cut it to shared path "S\BC...". So I've implemented code that saves the file in a path and then copy it to another path and then I deleted it from the first path (such that user never knows that I copy the file in other destination than desired destination).

How to load the PDF file, edit it, and save with the same name(automatically) in another path, in VB.NET?

I have a pdf format formular to be filled and saved with the same name. The pdf file should be loaded by calling the file in Adobe-pdfReader, then editing by operator and finally saving just by pushing the save button and automatically saving and naming by the software, not through saving-dialog.
Sort of.
Before you show the SaveFileDialog, set it's FileName property to the name of your file. The only problem with this is that the user could still change the file name themselves. The code is simply
SaveFileDialog1.FileName = "your file name.txt"
SaveFileDialog1.ShowDialog()
Unless you really need to have the dialog, you would be better saving it just using code. If you want to allow the user to choose the directory, use the FolderBrowserDialog instead.

save image automatically (coding) to resources.resx in vb.net

How can I create and automatically save a picture to resources.resx in vb.net?
I tried but it only saves to the resources folder. What I want is to automatically save it to the resources inside the vb. Thank you.
I don't know if this is possible, but why don't you just save it to a custom folder? Maybe even in your application folder (Debug) so that you only have to access it with it's name.
I suggest you save it in a folder that you make in your debug folder, maybe call it Images. Then just save the image to the folder and you're done. After this you will always be able to access this image with dim ImagePath as String = "Images/yourpicture.jpg"
I assume you know how to save an image?
Image.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Jpeg)

How to open a file from a stream in Notepad

To open a file I could do this like
Process.Start(fileName)
For this it is necessary that the file exists in the file system. Now I use a XmlDocument object and want to open the content in an external program like Notepad. I save the xml content in a stream but have no idea how to show it in another program.
Dim MyXmlDocument As New XmlDocument
'do something with the document
MyXmlDocument.Save(MyXmlStream)
If it isn't possible I have to save it first and open it in a second step. I only want to avoid the saving of the file in the file system.
I think it is necessary to save in the file system. However, you could create a temporary file and execute a delete command when you're finished with the file. This way it does not clutter the FileSystem. The AppData folder is a good place to start.