Embedding a PDF as a resource in WPF application - c#

I want to embed a PDF file (which is basically have Product details, Release notes) and wants to open that file from menu bar. What would be the best approach. I need to use this file in installer also. So i'm looking for an approach in which file will be moved to BIN on compilation and from there installer can access that file.
IDEAS ...

Add the file to the project the builds the EXE (use Add existing file in visual studio). Then right click on the file in visual studio, go to properties, and verify that the build action is "Content" and the copy to output directory is "Always" or "If newer" (whichever suits you).
Then this file will always be copied to the same directory where the EXE resides and your application will be able to access it because it's always in the application's directory.
If the installer just takes the BIN directory then it will also be able to access it because the file will reside in the BIN directory.
Have fun!

Finally i did it in following way:
a. We've a folder which contains notes.pdf (used by installshield).
b. Created a pre build command to copy the pdf file from installshield folder to output directory.
c. use process.start("notes.pdf"); to open the file. As it would look in bin directory first for pdf file and we've already copied it there.
It worked for both Installer version and running application from code.

Related

WPF Publish - include folders

I have a WPF project that is now finished, and I want to publish the app into an installer that other people can use.
When I publish the project, the project compiles into setup.exe, but on install the folders that I have do not get included.
I've been reading the guides, and made sure to include the files inside the folders as Content or a Resource. I've also made sure they are always copied. When some of my files are copied, they have a .deploy extension, and I need it to be an .xml in order for some function to read them. Images that I have in the app load fine however.
What do I need to do to have my custom files be EXACTlY as they are, xml as xml, txt as txt and so on. Also I have some empty folders, like this TempCF that I use at some point. Do i need to create it via code?
If you go to Project->Properties->Publish->Install Mode and Settings->Options->Deployment in Visual Studio, there is a "Use ".deploy" file extension" option that you can untick to get rid of the .deploy extension being added to your published files:
Empty project folders are not included in the output. Either put a dummy content file in them or create the folder dynamically as needed during runtime.
# Nikola L.
You could try to use the following methods to add the files in your program to the installation package so that you can have the files you need in your installation path. If I misunderstood your question, please let me know.
The steps are as follows:
1.Right-click on the Setup project and select View -> File System
2.In the File System page, right-click the Application Folder (File System on target Machine) and select Add->Folder(named User's Application Data ) -> Fileā€¦-> find the file under your project and select the file you need.
Such as:
3.Right-click the Setup project.
Install your setup package.
You can find the files you added in your installation path.
The result is like the picture below:

User manual text file not available in the exe version

I've just made my program an exe via publish in visual studio. In that i included a usermanual.txt and a aboutus.txt file which are in bin>debug folder. After i published the program and run it. Those files are not viewing saying cannot find the file. How can i fix this
Make sure your files are included in Solution Explorer. If not, add them (Right click on project -> Add -> Existing item... then select them from disk).
This way your manuals will be part of your project.
Then, you should setup that those files are copied to same folder as your exe (bin\debug or bin\release). To to that right click on them, select Properties and notice Copy to output directory setting. It has to have "Always" or "Copy if newer" option selected.
In your code, to open file, use path like this:
string userManualPath = Path.Combine(Application.StartupPath, "usermanual.txt");
that will open file in same directory as application's .exe.
When editing your manual (adding some new text), edit the one in solution, and the changes will reflect to either debug or release or published version.

ASP.NET: Publishing Website doesn't publish Resources folder

I have a website that I'm developing with ASP.NET. I'm using Visual Studio 2015. When I right-click and hit publish website the site publishes correctly except that my resources folder gets left behind. Heres what the solution explorer looks like in Visual Studio
But after I publish it here are the files that get put on Azure (accessed via FileZilla)
How do I tell Visual Studio to publish the Resources folder with the rest of the website?
Likely Answer
Open the Solution Explorer.
Right click one of the files in the Resources directory.
Choose Properties.
You now need to set two properties.
Build Action Content
Copy to Output Directory Do not copy
Do this to all the files that you would like to publish as content to the web server.
File Properties for Web Server Content
Remarks on File Properties
The Build Action property indicates what Visual Studio does with a file when a build is executed. Build Action can have one of several values:
None. Not what you want. The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file, that you do not want to publish to the web server.
Compile. Not what you want. The file is compiled into the build output. This setting is used for code files. In other words, we compile the file and the stick it into the bin directory.
Content. This is what you want. The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file. The "Content output group" is a list of files that Visual Studio will publish while also maintaining the same directory structure.
Embedded Resource. Not what you want. This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files. In other words, it not only goes into the bin directory but is also embedded within a .dll or .exe file.
Copy to Output Directory. This property specifies the conditions under which the selected source file will be copied to the output directory. The output directory is normally the bin.
See Also
What are the various "Build action" settings in Visual Studio project properties and what do they do?
File Properties on MSDN
If like me you are using Visual studio 2019, just right-click on the folder and select publish "name of the folder"
Steps to add resources to be published (Visual Studio 2017):
1) Right click the resources folder and select "Include In Project"
2) Now you should see Build Action: Content on the properties for the images.
Make sure the contents of your Resources folder have the proper "Copy to Output Directory" property. Right click the files you want to copy over, select Properties, then in the Advanced section look at the value under Copy to Output Directory. Generally this is set to "Do not copy" by default since most things get packaged up in the .dll. Change it to "Copy if newer" to get it to bring over the file. It'll bring over the folder structure as well.

Copy "Filesystem on Target Machine" to bin/Debug and bin/Release

I did a lot of googling, but didn't find any answer for this problem so far...
I defined the File System on the Target Machine for my program in Visual Studio 2010.
It includes all of the external Files (like XML's and batch files) which are needed to run the program. The files are stored in the Program Files folder.
The thing is now that if I try to debug my program, it says that it can't find the needed files in MyTool/MyStartProject/bin/Debug.
Is there any way to tell visual studio that it must copy these files to the Debug and Release folder to run the program?
I don't want to copy all files to the bin folder every time I want to run my program.
Thanks for any hint!
EDIT:
This is how my 'File System on Target Machine' looks like:
I created it using the built-in editor and Drag&Drop of the files and folders I need.
Add the needed files to your project, and for each file, open File Properties pane, select "Copy always" in the Copy to Output directory property.

How to copy a file to application folder in set up project during insatllation. File is in set up folder

I have a xml file in the setup folder of a windows application. Now during the installation how do i copy this file to my application's folder so that it can be copied to this path C:\Program Files (x86).......
I can not add the file to the application folder in the setup project because the content of file might change after build of setup project.
Its an external xml file in located inside set up folder. and I want to copy this file on installation path(C:/Program Files...) during installation. I will give this file with msi installer in side installer folder.
Please provide any idea if someone have....
If I'm understanding you correctly, this might solve your problem, or at least get you started:
Include the file in the main project (for instance in a folder called "resources"). Right click the file in VS, choose properties, and set Copy to output directory to Coppy Always.

Categories