User manual text file not available in the exe version - c#

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.

Related

How can I fetch a file to be read in StreamReader and listed in a ListBox? [duplicate]

Task is to form Visual Studio 2010 project so, that during any build or publish some foo.exe utility should be copied to output (bin) directory.
Early I have made PostBuildEvent task in .csproj (MSBuild-file):
<PropertyGroup>
<PostBuildEvent>
Copy "$(SolutionDir)Tools\foo.exe" "$(ProjectDir)$(OutDir)foo.exe"
</PostBuildEvent>
</PropertyGroup>
But this is not universal. During publishing (Visual Studio 2010) foo.exe appears in bin directory, but is not copied to output publish directory. Maybe I do everything completely wrong and there is standard mechanism to include files in projects to be later, during build or publish, copied to bin?
There is and it is not dependent on post build events.
Add the file to your project, then in the file properties select under "Copy to Output Directory" either "Copy Always" or "Copy if Newer".
See MSDN.
I only have the need to push files during a build, so I just added a Post-build Event Command Line entry like this:
Copy /Y "$(SolutionDir)Third Party\SomeLibrary\*" "$(TargetDir)"
You can set this by right-clicking your Project in the Solution Explorer, then Properties > Build Events
In Solution Explorer, please select files you want to copied to output directory and assign two properties:
- Build action = Content
- Copy to Output Directory = Copy Always
This will do the trick.
Add the file to your project.
Go to the Properties of that file.
Set "Build Action" to Embedded Resource.
Set "Copy to Output Directory" to Copy Always.
There is another way that can copy items that are "outside" the Solution (which also makes it technically possible to copy Solution Items as well).
In Solution Explorer, right-click in your project and choose "Add... Existing Item". Locate the file in question (it can by any type, not just code), and next to the "Add" button, click the drop-down arrow and select "Add As Link".
In Solution Explorer, select the item that was just added to your project and change the Copy to Output Directory property to Copy if newer or Copy always, as appropriate.
In my case, setting Copy to Output Directory to Copy Always and Build did not do the trick, while Rebuild did.
Hope this helps someone!
Try adding a reference to the missing dll's from your service/web project directly. Adding the references to a different project didn't work for me.
I only had to do this when publishing my web app because it wasn't copying all the required dll's.
Just so my fellow neuronically impaired comrades might chance upon it here, I had assumed that, for web projects, if the linked file was an external .config file that the "output directory" would be the same directory that web.config lives in, i.e. your web project's root. In retrospect, it is entirely unsurprising that it copies the linked file into the root/bin folder.
So, if it's an appSettings include file, your web.config's open tag would be
<appSettings file=".\bin\includedAppSettingsFile.config">
Duh.

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.

Deploy external file in c# solution with clickonce

I've a problem with Visual Studio Express 2010 c# edition.
I've a project that reference a DLL. This DLL has an external Excel file marked as
Build Action = Content
Copy to Output Directory = Copy Always
When I build the solution, this Excel file is correctly copied into BIN\release solution folder.
BUT if I try to deploy the same solution, with Publish wizard, the Excel file is not copied in the install directory.
Please, could anyone help me?
Open the Publish properties for your ClickOnce project. Then click on the 'Application Files ...' button. That launches a dialog where you can control which files are being included in the publishing package.
In order for your XLSX file (or any other non build file) to appear in that dialog you need to mark is as 'Content' in the Build Action of the properties window.
Are you saying that the Excel file is referenced only by the dll you are including in your project? That is a secondary reference, and ClickOnce will not see it and automatically include the file.
First, on your dll, I'm assuming it is referenced directly by your project. If so, then be sure you have added it to your project and set the Build Action to "none" and "copy to output directory" to "do not copy". Then delete your reference to it and re-add it, pointing it to the version now included in your project. Set the "copy local" property to "true". This will ensure the dll itself gets deployed correctly.
For the Excel file, you are going to have to add it to your project. Set the build action to "content" and set "copy to output directory" as "copy always". It will not be included automatically because it is a secondary reference to the ClickOnce app, not a direct/primary reference like the dll is.
Try to include this file into solution and set "Copy to Output Directory" to "Copy always"
It appears your file is not listed in the "PublishFiles" list. Open the Projects Properties, go to "Publish" Tab, click on "Application Files" button, make sure you see the DLL file in the list of files with Publish Status as "Include".
You could avoid the problem by inserting the Excel file as a resource, then writing it out like this:
File.WriteAllBytes(DestinationFileName, Properties.Resources.MyResourceFile);
I'm making an assumption that the Excel file is some kind of template you are using to build an output file from.

Link to config file in .Net setup project

I am creating an installer for my C# application, and I want to put a link to the configuration file into the start menu, so that users can open it for editing in notepad from the program folder in the start menu.
I seem not to be able to put a link to it however - does anyone know how to do this? (Really, I would just love to put "[targetdir]\myapp.exe.config but VS doesn't let me edit the field, only select from a file browser).
Many thanks,
Rob
I found the solution and it's pretty easy:
Add Project Output for your project in the setup project
Select Project Output from File System in left pane and go to the properties of the project output. Then add a filter *.config to remove the .config file from your project output.
Rename the app.config from your actual project to the output name that your App exe ([ProductName]) will have along with the config extension ofcourse.
Add the [ProductName].config to your setup project as a File.
Create a Shortcut to that file and add it in any setup folder desktop or program folder.
Voila.
You're all set.
Isn't the config file added in your installer? You should be able to select it when prompted for the shortcut target (the "Select Item in Project" dialog). Please note that in this prompt dialog you first need to browse to the folder which contains it (for example double-click "Application Folder").
If the config file is not added, you need to manually add it in "Application Folder". Only then you can create a shortcut to it.
Please note that Visual Studio doesn't support shortcuts to a specific file from a project output which generates multiple files. In this case you can try using a custom action which creates the shortcut through custom code.
I remember doing it in Vs2005 using as below:
File System Editor > Users Programs Menu
Add> Folder
Add file (Say Config file) point it to the its location

Embedding a PDF as a resource in WPF application

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.

Categories