Process.Start() – Open the file from the application after writing on the file

There are instances where you write to a file (say XML/Text file/word) fo debugging/testing etc.In those scenarios,your program finishes writing to the file and then you open the file manually in the application(IE/Notepad/Microsoft word) to see what the program has written in that file.You can actually launch that application after you finish writing to that file from with in the program making the whole process quick.The file opens in its default application right after you finish debugging without you needing to manually open it.
 

The steps:- (2 lines):-
 
a) Include the namespace:-
using System.Diagnostics;

b) Start the process for the saved file:-
//
//Code to save the file
//
 
// Following line would open the saved file in its default application
Process.Start("SavedFullFilePath");
 
 
Example:-
// Code to save the file
XmlDocument Xdoc = new XmlDocument();
string folderPath = @"C:\Ashish\";
string upload = folderPath + "2007.docx";
string savename = folderPath + "WordPackage.xml";
ZipPackage zipPackage = null;
byte[] packageData = null;
Stream stream;
packageData = GetBytesFromFile(upload);
stream =
new MemoryStream(packageData);
if (stream != null)
zipPackage = GetZipPackageFromStream(stream);
Xdoc = RRD.DSA.SCP.OfficeAssembler.
WordToXyXmlAssembler.ConvertToXyXml(zipPackage);
Xdoc.Save(savename);

// Following line would open the saved file in its default application (Internet explorer)
Process
.Start(strSave);

 
 
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Random Thoughts

The World as I see it

Simple Programmer

Making The Complex Simple

Ionic Solutions

Random thoughts on software construction, design patterns and optimization.

Long (Way) Off

A tragic's view from the cricket hinterlands

%d bloggers like this: