File path in app.config file ? Window application? - winforms

In window application, I am accessing one file and the file path is declared in app.config file. After that I create exe for that application. Now the problem is when path is changed in app.config file when setup is created is this changes updated in setup or not?. If yes, how can I do that?

Its better to use relative paths, but As I understand, you cant use they.
So, only one possible solution in my opinion - define file path during instalation or add special dialog on programm first run to let user to define the path.

Related

WPF: Image Path doesn't work after publishing

I have a trayicon in my WPF App. When I was debugging in Visual Studio, it works well:
System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = new Icon("../../logo,ico");
But after I published it, the App threw an exception saying it could find the path of the image of the trayicon. I've search a lot resources on online, I saw many solutions use pack, but it seems pack only accept Uri variable and the path for trayicon must be string. I also tried to create a folder called Resource under the project solution and put the image file into it. This was the same: worked while debugging but would not work after publishing..
So based on #WPF Germany's suggestion, I solved the path issue after publishing the App by Clickonce. However, if I copy a App shortcut to system startup folder, it would find the ico in C:\WINDOWS\system32, which is not easy to workaround since systems32 usually requires admin right to access. Any idea for that?
Did you check, that your logo.ico file is copied to output path?
In VS you have multiple options to provide your Resource files.
First option:
Select your logo.ico file in solution explorer and choose None as Build Action and Copy always at Copy to Output Directory (at file properties).
After compiling you will find the file in a subdirectory of our OutputPath.
use (if logo.ico is placed in your projects root):
ni.Icon = new Icon("logo.ico");
other option:
Use Resource as Build Action and build your Icon using a Stream created from Resources.logo...

How to put all the files used inside the winform application in the exe itself?

I am making a winform application whereby I am using some images to show .It works fine when run . But what if I want to take the exe out from the debug folder and use it in some other machine then it will give exceptions that it can't find images on the same path(its obvious as it is not there in that machine path).
Idea to overcome this is to make a setup out of it,but that too is a tedious task.
Can it be possible that we can accomodate all the other sources(like images) used in the project in such a way that it should go along with the exe ?
It's a kind of an odd error, because the *.exe file in the Debug folder is created after adding all the resources into it. And that's why the *.exe file gets lager in size. But it will be a problem if you have mentioned the paths of the resources (like images) manually.
To avoid that always use the properties panel to import resources to the project and this will create the Resoures.resx automatically. Then all the resources will stick to the *.exe file.
But if you have mentioned the paths manually you must provide them in the targeted computer which you are going to use the *.exe file. To make it more easier, give a path in the same folder where the *.exe file exist.
For example give simple paths like (#"image.jpg"), without giving paths like ("C:\Users\Sam\Pictures\image.jpg").
And create a setup including all the resources like images, databases, etc.

How link to any local file with markdown syntax?

I have a local markdown file containing several links and I want that links head to local file like pdf.
I use the following syntax:
[my link](file:///C:/my_file.pdf)
But when I open my markdown file into a Firefox page and click on the link, nothing happens.
What exactly have I missed? Is it possible to open local file?
None of the answers worked for me. But inspired in BarryPye's answer I found out it works when using relative paths!
# Contents from the '/media/user/README_1.md' markdown file:
Read more [here](./README_2.md) # It works!
Read more [here](file:///media/user/README_2.md) # Doesn't work
Read more [here](/media/user/README_2.md) # Doesn't work
How are you opening the rendered Markdown?
If you host it over HTTP, i.e. you access it via http:// or https://, most modern browsers will refuse to open local links, e.g. with file://. This is a security feature:
For security purposes, Mozilla applications block links to local files (and directories) from remote files. This includes linking to files on your hard drive, on mapped network drives, and accessible via Uniform Naming Convention (UNC) paths. This prevents a number of unpleasant possibilities, including:
Allowing sites to detect your operating system by checking default installation paths
Allowing sites to exploit system vulnerabilities (e.g., C:\con\con in Windows 95/98)
Allowing sites to detect browser preferences or read sensitive data
There are some workarounds listed on that page, but my recommendation is to avoid doing this if you can.
You link to a local file the same way you link to local images. Here is an example to link to file start_caQtDM_7id.sh in the same directory as the markdown source:
![start_caQtDM_7id.sh](./start_caQtDM_7id.sh)
After messing around with #BringBackCommodore64 answer I figured it out
[link](file:///d:/absolute.md) # absolute filesystem path
[link](./relative1.md) # relative to opened file
[link](/relativeToProject.md) # relative to opened project
All of them tested in Visual Studio Code and working,
Note: The absolute and relative to opened project path work in editor but don't work in markdown preview mode!
If you have spaces in the filename, try these:
[file](./file%20with%20spaces.md)
[file](<./file with spaces.md>)
First one seems more reliable
This is a old question, but to me it still doesn't seem to have a complete answer to the OP's question. The chosen answer about security being the possible issue is actually often not the problem when using the Firefox 'Markdown Viewer' plug-in in my experience. Also, the OP seems to be using MS-Windows, so there is the added issue of specifying different drives.
So, here is a little more complete yet simple answer for the 'Markdown Viewer' plug-in on Windows (and other Markdown renderers I've seen): just enter the local path as you would normally, and if it is an absolute path make sure to start it with a slash. So:
[a relative link](../../some/dir/filename.md)
[Link to file in another dir on same drive](/another/dir/filename.md)
[Link to file in another dir on a different drive](/D:/dir/filename.md)
That last one was probably what the OP was looking for given their example.
Note this can also be used to display directories rather than files.
Though late, I hope this helps!
Thank you drifty0pine!
The first solution, it´s works!
[a relative link](../../some/dir/filename.md)
[Link to file in another dir on same drive](/another/dir/filename.md)
[Link to file in another dir on a different drive](/D:/dir/filename.md)
but I had need put more ../ until the folder where was my file, like this:
[FileToOpen](../../../../folderW/folderX/folderY/folderZ/FileToOpen.txt)
If the file is in the same directory as the one where the .md is, then just putting [Click here](MY-FILE.md) should work.
Otherwise, can create a path from the root directory of the project. So if the entire project/git-repo root directory is called 'my-app', and one wants to point to my-app/client/read-me.md, then try [My hyperlink](/client/read-me.md).
At least works from Chrome.

Include data files in a Silverlight app

I have some XML files marked as "Content" that should be copied into the application's XAP file. How can I read these files from within Silverlight?
I know how to read files normally in .NET. So what I'm looking for is a way to find where Windows stuck the files and any realavent security issues.
This is not exactly how to read files from within the xap but if you just want to be able to load the files at runtime then this will work.
You can set the files to be embedded resources. You then get access to them using the following:
GetType().Assembly.GetManifestResourceStream(resourceName)
resourceName is the name of the file with a full namespace. E.g. if your assembly default namespace (set in project settings) is "foo" and your file is in a folder called "bar" then resourceName would be something like "foo.bar.MyFile.xml"
You should just be able to do an XDocument.Load an pass in the name of your file.

visual studio 2010 how to reference a folder inside a project?

I have added a folder with a bunch of images inside my vs2010 project.
I want to reference this folder through code.
Since the final prog may be deployed into different location absolute path won't do!
What is the standard way to get the folders relative path?
I am fairly new to this, so sorry if I am asking something too obvious!
Thank you.
You might want to add images to the resources file, so you will be able to work directly with an image without writing code to find the file.
Anyway, you can get the application path:
string appFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
And then you can use methods from Path class, like Path.Combine to refer to the folder.
Resources is a good idea. An alternative is to have the Application's installed folder location written to the Registry when the application is installed. OR do something like
string dir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
If these images are relative to your executable, then you can either use argv[0] from main() (if it's command line), or even better follow what MSDN is advicing:
By convention, argv[0] is the command
with which the program is invoked.
However, it is possible to spawn a
process using CreateProcess and if you
use both the first and second
arguments (lpApplicationName and
lpCommandLine), argv[0] may not be the
executable name; use GetModuleFileName
to retrieve the executable name, and
its fully-qualified path.

Resources