Using files that are located under the project?
-
I have a two files lets say File1.BMP and File2.TXT which i want to write on the hard drive. How do i access those files that are included the project? I am looking to have these two files to be compiled into the executable and be extracted at a certain point in my application. I've tried looking around but have not found that much. Thank you in advance.
-
I have a two files lets say File1.BMP and File2.TXT which i want to write on the hard drive. How do i access those files that are included the project? I am looking to have these two files to be compiled into the executable and be extracted at a certain point in my application. I've tried looking around but have not found that much. Thank you in advance.
You can add them to resources. All you have there is embedded in your app executable. However you can't easily extract them to a folder. You can use an installer to do that. To add anything to resources just go to the properties folder under your project (in the solution explorer) and edit the Resources.resx file. You can add existent or new files. After you add them you can access them through Properties.File1 for example. Cheers,
rotter
-
You can add them to resources. All you have there is embedded in your app executable. However you can't easily extract them to a folder. You can use an installer to do that. To add anything to resources just go to the properties folder under your project (in the solution explorer) and edit the Resources.resx file. You can add existent or new files. After you add them you can access them through Properties.File1 for example. Cheers,
rotter
rotter512 wrote:
However you can't easily extract them to a folder.
Wrong, mooselips...
ResourceManager rm = new ResourceManager("AppName.Properties.Resources", Assembly.GetExecutingAssembly()); // and if the viewer swf file doesn't already exist in the folder byte\[\] stream = (byte\[\])rm.GetObject("MyResource"); string filename = "myresource.bmp"; if (stream != null) { // and write the file to disk try { using (FileStream streamTarget = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) using (BinaryWriter writer = new BinaryWriter(streamTarget)) { // make the file hidden when it's created on the hard drive (included because it's cool) File.SetAttributes(filename, File.GetAttributes(viewerFile) | FileAttributes.Hidden); // write the contents writer.Write(stream); } } catch (Exception ex) { if (ex != null) {}; } }
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001modified on Monday, August 25, 2008 11:18 AM
-
I have a two files lets say File1.BMP and File2.TXT which i want to write on the hard drive. How do i access those files that are included the project? I am looking to have these two files to be compiled into the executable and be extracted at a certain point in my application. I've tried looking around but have not found that much. Thank you in advance.
Look at my reply to rotter512... Once you add the files as resources and compile the app, it's a piece of cake to extract them at runtime.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
rotter512 wrote:
However you can't easily extract them to a folder.
Wrong, mooselips...
ResourceManager rm = new ResourceManager("AppName.Properties.Resources", Assembly.GetExecutingAssembly()); // and if the viewer swf file doesn't already exist in the folder byte\[\] stream = (byte\[\])rm.GetObject("MyResource"); string filename = "myresource.bmp"; if (stream != null) { // and write the file to disk try { using (FileStream streamTarget = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) using (BinaryWriter writer = new BinaryWriter(streamTarget)) { // make the file hidden when it's created on the hard drive (included because it's cool) File.SetAttributes(filename, File.GetAttributes(viewerFile) | FileAttributes.Hidden); // write the contents writer.Write(stream); } } catch (Exception ex) { if (ex != null) {}; } }
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001modified on Monday, August 25, 2008 11:18 AM
He said easily. :P
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
You can add them to resources. All you have there is embedded in your app executable. However you can't easily extract them to a folder. You can use an installer to do that. To add anything to resources just go to the properties folder under your project (in the solution explorer) and edit the Resources.resx file. You can add existent or new files. After you add them you can access them through Properties.File1 for example. Cheers,
rotter
You can also add the files directly to the project and set their build type to "embedded resource". I'm not sure if that results in the same thing or something different, but they'll definitely be embedded in the file.
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
-
He said easily. :P
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-
That *is* easy.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
That *is* easy.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Anything dealing with streams is, imo, not "easy". "Possible" would be more appropriate. To me, easy would be: ResourceManager.CopyToFile( filePath ); But I guess you meant easy for you.
“Time and space can be a bitch.” –Gushie, Quantum Leap {o,o}.oO( Looking for a great RSS reader? Try FeedBeast! ) |)””’) Built with home-grown CodeProject components! -”-”-