Help_File in C# - c#

I'm using MS Visual Studio Pro 2012 and I want to create some kind of help file.
I was thinking in create a html file like this but my question is: Do I need to have the html file always in this directory, even after I have the .EXE file created or the html file is added to the .EXE file?
If not, how can it be done?
[.NET Framework 4.5 | Windows Forms]
EDIT : I want to load a given (local) html file in the default web browser. This file should be 'inside' the .EXE file.

If you're looking to build a help file from Visual Studio, why not look at:
http://shfb.codeplex.com/
Sandcastle will build your help file based on the comments you have written on your classes and methods. Hit the forward slash three times (e.g. /) above your class or method declaration and the comment box will appear. Populate with salient details, run Sandcastle, and your help file will be generated.

The advantage of having a separate HTML file is that you can update it on it's own without pushing out a new assembly. However if you want to build it into the EXE, you can go to your project properties, then click on Resources. Add an existing file (your HTML file) and it will now be accessible from your code.
When you want to open it you can do something like this
string html = Resources.MyHelpFile;
if (!File.Exists("tmpHelp.html"))
{
using (var tmpFile = File.CreateText("tmpHelp.html"))
{
tmpFile.Write(html);
}
}
Process.Start("tmpHelp.html");
You can then delete the help file at a later stage such as when the user closes your application.

I'll recommend using HTML Help Workshop to create the help file. and then use Help.ShowHelp();. Its a lot more easier
But for your case. You can either do as KeyboardP suggested or move the file to your bin/Debug folder and then use
Process.Start("helpname.html");
NOTE : You'll also need to add the file to the Application Folder when you're creating your setup.

You can build html file (I think the most easy way it's to create it via microsoft word and to save as html)
Then you make a new form contain webBrowser tool and set the URL to your html file path, like this:
string filepath = Environment.CurrentDirectory + #"\Help.htm";
Uri uri = new Uri(filepath);
webBrowser_Help.Navigate(uri);

Related

How to add or use .docx template file as a resource or reference in c#?

Im trying to make a winapp that fills the document template file using the C# form and create a new .docx file. Where should i put the .docx file and how should i use it. I placed my template inside the Debug folder and load it like:
dox.LoadFromFile("template.docx");
Im having a problem when using the executable because it doesnt seem to find the template.docx
It is possibly to have files copies into the Output Directory. This is a simple mater of setting the File up accordingly.
However, having data like this in the Programm directory is frowned upon. As of Windows XP, you are unlikely to get write access to those files anymore. So any form of changes would be blocked unless your programm runs with full Administrative Rights.
The intended place for such files are the SpecialFolders. On those you are guaranteed write rights to some degree. While you could still store the template in the programm directory to copy it there if needed, it might be better to use copy it to default user as part of hte setup process.
Of course Visual Studio loves to run code under rather odd user accounts. So I am not sure how far that works for testing.
You can store you word document directly in your assembly (juste copy past the file in your project).
Then you just copy it to windows temp folder before doing your own business. Just don't forget to delete the file in the temp folder when you are good because windows won't do it for you.
Dim fileLocation As String = Path.GetTempFileName()
Using newFile As Stream = New FileStream(fileLocation, FileMode.Create)
Assembly.GetExecutingAssembly().GetManifestResourceStream("YourAssemblyName.yourfile.docx").CopyTo(newFile)
End Using
...
System.IO.File.Delete(fileLocation)

Opening a file (doc, pdf) via a button or hyperlink

I feel like I've gone in a thousand circles on this and it should be much simpler than it is, but basically I have this simple resume submission page in asp.net using C#. The files are on the server in a folder but it seems every solution I find just does nothing at all when I try to execute it.
Here's some examples of some of the things I've tried:
string folder = "~/App_Data/Resumes/" + Session["ResumeName"].ToString();
string folder2 = Server.MapPath("~/App_Data/Resumes/" + Session["ResumeName"].ToString());
System.Web.VirtualPathUtility.ToAbsolute(folder);
System.Diagnostics.Process.Start(folder2);
I'd never imagined something as simple as opening a document from a server would be so difficult. Is it not possible to just simply have a link to a document and have it opened when the user clicks it? That's all I want to accomplish. Thank you reading my through my frustration.
To clarify, System.Diagnostics.Process.Start(folder2); works locally, but doesn't work on the web server. I want this to work on the web server so that's why that one is out. I've tried to make it possible for the web server to open that file but I don't think I know enough about IIS to make it happen.
App_Data is a protected folder in ASP.NET. IIS will not serve anything from that folder directly to the client-- you will need to build a handler that serves the document directly.
Here are a few samples, though they aren't representative of everything you need to do. Others can feel free to add additional resources. Your handler would have to open the file and write it to the output stream:
Using a c# handler to serve up wav files cuts audio short (only a couple of seconds)
ASP.net cache ASHX file server-side
Don't use folders like App_Data to have your downloadable resources .
There is a similar question on stackoverflow which will give you a exact step by step answer - ASP.NET file download from server
From the title of your question, If I understand correctly you want to open a .doc or .pdf on a link or button click. This will open the respective document on the client.
<a id="lnkResume" href="#" runat="server" target="_blank">Download Resume</a>
And you can set the dynamic resume name from the code like below
string fileName = Session["ResumeName"].ToString();
lnkResume.HRef = Server.MapPath("~/App_Data/Resumes/" + fileName);

How to implement a text file in content (XNA)

I am building a game which loads its map from a text file.
While creating the parts that handle maps, I simply kept the text file in the content folder and fetched it by its Windows filepath. This won't work for proper deployment (or even running the game from different drives) because it requires that the filepath be exactly the same.
I looked around for a way to include the text file the same way I would a Texture2D, but I cannot find any class that allows me to use it. Some answers to other questions suggested that I just use the text file from my content folder? How would I do that? My program's name is IslandQuest (placeholder; it doesn't even involve an island) so would I place the text file in the IslandQuestContent folder generated by XNA Studio? How would I access it from there such that its filepath doesn't depend on the drive configuration of a computer?
Thanks for any help.
This may not be the best way to do this but just looked back at what I did in my first year at university with XNA,
I added my txt file to the contents folder. Then in the properties for the file (select it in the solution explorer and view properties window) there should be "Copy to Output Directory", make sure this is copy if newer.
Then its just a case of
string.Format("Content/{0}.txt", filename)
I do think this can be improved perhaps by the following but it is untested
Path.Combine(Content,filename +".txt");
In my case I was reading XML file files from a data folder in my main project.
So under my project in Solution explore I had this set up:
WindowsPhoneGame1
...
data/
content.xml
Game1.cs
Program.cs
etc...
Where properties for content.xml were Build Action: Content and Copy to Output Directory: Copy always
In the class that read the file I used TitleContainer.OpenStream Method which according to the docs:
Returns a stream to an existing file in the default title storage
location. .... The stream returned is read-only. The file to be read must already exist, or this method will fail.
My example code
//open stream
Stream stream = TitleContainer.OpenStream("data/content.xml");
//do something with it...
Create a "Content" folder in your main project.
Put the files that cannot be put in the Content project in there.
Be sure to set all your content Build actions to Content and Copy Always.
The Content folder from your main project and the content in the content project will end up in the same folder when built.
The file path would still be "Content/file.ext" or whatever.

Checking source file and automatically generating resx file

Hello everyone here is my problem. I have the source file of a web page and it will be translated into different languages, so there are lots of meta:resourcekey keywords everywhere as you can imagine.
What I want is a plugin in VS that will first create a resx file and then check the whole code and whenever it sees the "meta:resourcekey" it will add a new string in the resx and copy whatever it sees on the right of "meta:resourcekey"
Can anyone help?

initiating a string from a config file

I am asked to do this and I have no clue from where to start since I am new to it.
I have created a C# .NET application (a web api to be more precise) using Visual Studio 2012.
I created an lsi file ( the new version of msi files) to be able to deploy it on a server.
Now I want to create some sort of a configuration file where I can edit a string without having to go into the code every time to change it every time.
lets say the variable is called mystring:
1- how can I create a config file that request a string without having to go into the code?
2- how can I say the mystring=input string ?
I tried to look it up but since I don t have the exact name I don t really know what I am searching for ...
Thanks,
One solution would be to save a configuration file with the settings you want to load, I'd suggest saving it to the ProgramData folder.
I would save the settings to an XML file (or JSON) so you can serialize and deserialize the data into your program when it loads. Guide
You can also save other details so they'll persist each time the application is opened this way, such as a username field.

Categories