How to open a file from a stream in Notepad - vb.net

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.

Related

How do I embed an exe file in an MS Access Form and Run it at run time?

I'm using MS Access 2003 for Special and old problems with the .mdb project
I want to embed my files like .txt or .exe or .pdf and run them at runtime or write that on disk.
What have I tried :
enter image description here
I don't know what's the code to do what I need I couldn't find my solution on internet.
Private Sub Form_Load()
'Me.OLEUnbound2.Application.Run
Dim obj As Object
Set obj = Me.OLEBound1.Object
'obj.DoVerb (acPrimaryVerb)
End Sub
Update:
I wrote a C# program called BMH.exe, which I open and run through Access, but I want this file to be in my source in any way possible so that the user does not have to place this file next to the program or somewhere It has Windows,
I also don't want to do things like downloading from the site, creating an installation file, I just want to access this program in any possible way through the embedded file itself, which is in the form of OLE Object and from the Packager Shell class. Write the object to a specific address or run it directly from Access itself
You can save the file as attachment in attachement field. If it will not accept an .exe file switch the extension and switch it back when exporting, you can do all this with code. Alternatively you can store the file as binary in an Ole field.

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()

Reopen DOC file in write mode, with macro inside it

I am using a macro template for particular DOC files only. It runs only for these files and, as I assume, it is treated as the DOC file itself.
All I want is to remove the file OR clear the contents of it, after the macro finishes. The initial file is read-only.
I have tried:
SavingAs in TEMP folder, change file attribute of initial file and then try to Kill it - no luck, it seems that initial file is still preloaded(?) and does not know that the read-only flag was removed. Error: Permision denied.
When I try to Close the initial document, I am closing also the macro itself...
So:
Is there any way to (from the macro inside the DOC file) :
Reopen the file in write-mode? (so I could clear the contents afterwards)
Remove the initial file? (after SaveAs so I actually will have a new file in write-mode and will be able to remove initial file)

Create Folder and save file through fileopenDialog

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).

Opening a file in my application from File Explorer

I've created my own application in VB.NET that saves its documents into a file with it's own custom extension (.eds).
Assuming that I've properly associated the file extension with my application, how do I actually handle the processing of the selected file within my application when I double click on the file in File Explorer?
Do I grab an argsc/argsv variable in my Application.Load() method or is it something else?
Try this article but short answer is My.Application.CommandLineArgs