I need to open .HLP file by button click. i don't want to call .hlp from local folder like C:\ drive. i don't know where should i put .hlp file in my project. Please tell me with sample code.
i used this code :
Help.ShowHelp(this,"C:/Users/pushparajs/Downloads/TabbedMdiChildForms_src/TabbedMDIChildForms/helpfile/Properties/TTYUI.HLP");
You shouldn't need to specify the full path. Normally you just specify the file name, e.g. "TTYUI.HLP", and Help.ShowHelp(this, "TTYUI.HLP") is smart enough to look in the same folder as Application.ExecutablePath.
You can add a reference to your hlp file in your solution explorer, and open properties by right clicking, and specify to copy to output folder.
Related
I want to acess a .txt file, which I stored in the resources folder of my project, there where all the imported pictures are stored as well.
I want to use something like a relative path, since every user would have safed his programm somewehere else on his Pc, but there is always the resources folder at the same place, compared to the programm folder.
I tried to used this: displayText = System.IO.File.ReadAllText("Resources\\startmessages.txt"); but this isn't working.
I get this error message: System.IO.DirectoryNotFoundException:, it lists the unrelative path to the .txt there as well, so I don't get, why it cant read it.
Thanks for your Help.
What #ChetanRanpariya is trying to tell you is, that your programm is built in another folder than your folder Resources is sitting to. So you have explictly tell your file Resources\startmessages.txt to copy itself on build process, so it get copied to said another folder. Assuming that you are using Visual Studio, you have to right click on your file and set Copy To Output Directory to true. Its relative folder path (Resources\) will be taken over. You find your build folder somewhere in your bin folder depending on configuration and framework. :)
Current Path where your executable is
Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).FullName
Path to Solution
If you are using Visual Studio and need to access the folders in the solution directory, you can use .Parent method,
Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName
Use of Path.Combine
and once you have the location of your Resource folder, use Path.Combine to get the location to read files / content etc
Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.FullName, "Resources\\startMessages.txt")
Visual Studio 2017 (v15.9.9).
I can't seem to figure out how to create a .tfignore file. If I do it manually, windows tells me I need to add a file name. And I am not seeing anywhere via the IDE to create one.
I'm used to GIT, where I can right click on a pending check-in file (that has changed) and just select "Ignore". But I don't seem to have that option, despite the fact that all the results I find via Google tell me that I should.
You can create your file as .tfignore.. The last dot will be removed automatically.
This can be solved using the same steps as How to create .gitignore file (just replace .gitignore with .tfignore):
Create the text file tfignore.txt
Open it in a text editor and add your rules, then save and close
Hold SHIFT, right click the folder you're in, then select Open command window here
Then rename the file in the command line, with ren tfignore.txt .tfignore
However, an easier/quicker way to get around this Windows Explorer error is by appending a dot to the filename without extension: .tfignore. will be automatically changed to .tfignore
the easiest way is to open command prompt and navigate to your project folder. Then
notepad .tfignore
after that just save file and you are good to go.
Or you can also use
echo "" > .tfignore
Note that you may need to manually include this file to TFS
For example, lets say I have a text file with one line of code named Template.txt included in the project folder.
Since the text file is included with the project, is there another way to specify this file or would I still have to specify the full file path?
If it's included in the project and if you select the option copy always from the property Copy to Output Directory (Right click on the file and select properties in VS), you will have the file available in the bin/ folder after compilation. So, you would not need the entire path. Just the name of the file.
If i understand your question,
you can put the file on the same folder where the exe file is and specify only the name of the file [Template.txt].
I added picture box to my form and import 2 pictures, from properties under image property i choose the first picture when the application starting and inside my start button event i want to change my picture to the other picture.
this is what i have try:
pbIndicator.Image = Image.FromFile(#"..\Resources\indicator_green.png");
but file not found exception error occurs.
You should be able to do something like this:
pbIndicator.Image = Resources.indicator_green;
Be sure that in the property window if the Build Action is on Content, and Copy to Output Directory is on Copy if newer.
If you want it to be content. Else use the answer Shadow Wizard gave.
As I wrote in the comment if indicator_green.jpg is an image included as resource via resource file (Resources.resx) then it won't be copied to output directory (it means it's in your project folder because it's used to build executable but it'll be embedded inside your assembly, not deployed standalone).
Resource files will (by default) place resources you add inside Resources folder (and then linked). You can always access them using generated code file for resources:
pbIndicator.Image = Properties.Resources.indicator_green;
You may change namespace Properties and property name according to what you have in your project (by default property name has the same name of the resource and then same name as original file).
Of course you're not forced to embed your resources in your assembly. If you want to deploy them as standalone files just right click Resources folder and add an existing file. In the properties window for that file select Copy always for Copy to output directory and et voila, you'll be able to read it with:
pbIndicator.Image = Image.FromFile(#"Resources\indicator_green.png");
Please note that Resources folder won't be a sub-directory of your output directory (do not forget that source files are not part of installation).
Anyway I suggest you do not build path like that, little bit better would be to do not rely on current folder:
pbIndicator.Image = Image.FromFile(
Path.Combine(Application.StartupFolder, #"Resources\indicator_green.png");
You're not limited to Resources folder, you can do that with any folder (and with any name).
I have written some code for saving an image to a folder in asp.net. My problem is that the image in the folder is white and is not the same as images added manually to the folder.
I used a simple asp.net fileupload control to save the file to the correct path. But the images dont display on the page and this is how the file icons look in visual studio.
Anybody know why this is?
Try Right-clicking the images and select "include in project"
edit
If you want to do that programmatically you need to modify the project file programmatically; that's all there is to it. It's an XML file with nothing special about it. Note, however, that you have this under source control and you'll probably need to do more than just modifying the project file (ie adding the file to source control too)
Yes, it is. Because it is not included as part of the project files.
Try this:
There isn't anything else that is wrong. Only the files are not tracked by VS, so they won't be published. Your files are still completely accessible from your code.
In my opinion, files like say images added to your web app shouldn't be part of the project.
You need to include them in the project by right clicking them and click Include In Project.
Furthermore, if you want these files to included in the build you need to go to Properties of each file and set Build Action as Content.