How do you output a resources file from C# application? - c#

I am using Visual C# 2010 Express. I would like to put .dotx or Word Template files into the Resources folder of my application and when it is installed, output the files to a different directory preferably C://Myfolder/. I couldn't find anything about it here. Are there any ways to solve this?

Why would you want this as a resource? Why not bundle it as part of the installer package which can work out where to put the file when your application is installed?

Click on Resources (in "Properties"), and then on the arrow next to "strings" and choose "files".
Then drag the file in and name it. then use:
Properties.Resources.fileName;
which will be a byte[], and save it using:
File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + #"\filename", Properties.Resources.fileName);

Related

How do I hide all the extra files from a published windows forms project in visual studio?

I want to publish to my desktop a little app I've been working on in visual studio but when I publish it there are also some other files like the .dll or the .pdb files without which the app does not run and I don't want those cluttering my desktop so can I somehow integrate them in the app itself or put them in a different folder?
I've tried looking for answers on youtube but all the videos are from like 2015 so they don't work and all the tutorials made by Microsoft are either not what I'm looking for or too technical for a beginner cs student to know if they are or to follow along.
If you want not to publish the .pdb file ,you just need to add this in the app.config file:
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
Since you are a c# student, I think what you need to do is just to right-click the .exe file after publishing to create a desktop shortcut:
Or add the following statement in the post-build event:
xcopy "$(TargetPath)" "C:\Users\Administrator\Desktop"
$(TargetPath):The absolute path name of the primary output file for the build (defined as drive + path + base name + file extension)
The following path is the path you specified, and you can change it according to your needs.

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:

Open pdf file dynamically from toolstripmenu c# winform

i'm trying to open a pdf file from my winform application, while the pdf file is in the directory of the application. I want to pack this app latter so I can open them dynamically even if the app is installed in another machine. I'm using Process.Start(".\file.extension") but I'm getting the error: The system cannot find the file specified. I heard that I need to send it in System32 folder but when I pack it I have no idea how to send it there. Hope you understood and can come with a solution for this problem. Thanks in advance.
If the pdf file is inside the project itself, You can simply do this:
Your PDF File as seen from the solution explorer > Right Click > Properties
Copy to Output Directory > Copy Always
After this, each time you build your project or when you deploy it, The PDF file will always be included in the project output folder.
Try this...
string commandexec = string.format("{0}\{1}",AppDomain.CurrentDomain.BaseDirectory,filename);
Process.Start(commandexec);

embed xml in custom controls

i create a custom Control and using the XML file now i need to have just one dll file to use that to another project can you help me to embed xml file to my custom control project?
my programming language is c#.net
If you are using Visual Studio (My version is 2008, if you have 2010, this might be slightly different.)
Open properties for your DLL project.
Click the Resources tab.
Click the blue link (if there is one to add resources to your DLL).
Top Left with the little down arrow choose files.
Click Add Resource, find your file and add it. Give it a name like XmlFile with no dots, this is your handle to the file.
Save and Close Properties for the DLL.
Then somewhere in your project you will use this line, or something like it to access your file.
XElement root = XElement.Parse(Properties.Resources.XmlFile);

For a Silverlight 4 Visual Studio solution, what needs to be in version control?

I have a Silverlight 4 app that I'm building with Visual Studio 2010. I'm using Mercurial/TortoiseHG to do version control. Which files do I need to check in? By default, it checks in all sorts of .dlls in /bin/debug and stuff. Do I really need those? Or can I just grab code and content files? Do I need to version something to keep track of project properties and references, or is that contained within the .csproj file itself?
You don't need to include stuff in /bin or /obj. This is true of all VS solutions in source control. These are recreated upon every rebuild. Also, for Silverlight specifically, you don't need to check in the XAP file that is generated in the ClientBin of your web app.
From MSDN (via this social.msdn thread):
You can add the following files to Visual Studio source control:
Solution files (*.sln).
Project files, for example, *.csproj, *.vbproj files.
Application configuration files, based on XML, used to control run-time behavior of a Visual Studio project.
Files that you cannot add to source control include the following:
Solution user option files (*.suo).
Project user option files, for example, *.csproj.user, *.vbproj.user files.
Web information files, for example, *.csproj.webinfo, *.vbproj.webinfo, that control the virtual root location of a Web project.
Build output files, for example, *.dll and *.exe files.
It doesn't say anything specific about Silverlight projects though.
Is Mercurial/TortoiseHG integrated into Visual Studio? i.e. can you check out/submit from within VS?
If so, if you right click on the project name and select "Add Solution to Source Control" it should add those parts of the project that it needs ignoring everything else.

Categories