I always prefer to develop some lil utilities to make lot of
people's life easy, including myself </smile>... For
instance I have developed a utility to create backup of sharepoint's sites. And
some other utilities like creating insert queries scripts for data in a table,
arranging and putting "& _ " in strings of huge SQL queries, and so on..
Sometimes there is a need to add some supportive files to these
utilities. There
are different techniques to do this but the one is use quite often is that I
embed the file in the assembly and at runtime I get it out from the assembly and
use it as required. For example in case of creating site backups of sharepoint,
a file "stsadm.exe" is required which does all the job. so I include the file in my project and set
the Build Action property to Embedded Resource. Then
later use the following code to get it out from the assembly.
|
Dim
Strm As IO.Stream
Dim
Buffer() As
Byte
If
Not
My.Computer.FileSystem.FileExists(filename)
Then
Strm =
System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(Root Namespace.filename)
ReDim
Buffer(Strm.Length)
Strm.Read(Buffer, 0, Buffer.Length)
Strm.Close()
My.Computer.FileSystem.WriteAllBytes(filename,
Buffer, False)
Buffer = Nothing
End If
|
There is a new property introduced in VS2005, Copy to Output
Directory. You can set the property according to you need.
And hay has anyone checked the new namespace,
Microsoft.VisualBasic.Devices, added in 2.0?? In the code above I have
used it couple of time. My.Computer.FileSystem.FileExists and
My.Computer.FileSystem.WriteAllBytes. Try it, it got some good stuff to
explore.