Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,
I am making an wpf application.
in that i am reading some files that exist in physical location of computer.

so in my application i wrote path for file like

C:\Users\shorts\Desktop\nnn\bbb\sss\swa.txt

but if i am using my application into other pc it gives error.

then i added all file into solution explorer

and gave path "..\files\swa.txt"

its also not working.

please suggest me something.
Posted
Updated 13-Dec-13 22:45pm
v3
Comments
What is that error?
jackspero18 14-Dec-13 4:32am    
copy and past that file in your application folder then give dynamic path like "..\files\swa.txt"
bunty swapnil 14-Dec-13 4:48am    
if writing in this type getting error coudnt find this path.
JoCodes 14-Dec-13 4:48am    
Use always a relative path

You can use Application.StartupPath and then build the relative application path in a windows application.
 
Share this answer
 
The remedy in this situation is (probably) to fix the file paths you write to on all machines running your Application so they are "context independent."

Writing files relative to one of the Special Folders referenced by .NET's Environment.SpecialFolder enumeration is a safe way to go [^].
 
Share this answer
 
just make folder and put all files in that folder in your application
then use it will works
 
Share this answer
 
You should use relative path, not absolute path. Here's the code that you can get the project working directory:
System.Reflection.Assembly.GetExecutingAssembly().Location
 
Share this answer
 
try this code
C#
Bitmap bmp = new Bitmap(pnControls.Width, pnControls.Height);
            pnControls.DrawToBitmap(bmp, pnControls.Bounds);
            int folderName = 0;
            newPath:
            folderName = folderName + 1;
            string path = "E:\\Test" + folderName;
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                bmp.Save(path + "\\ID_CARD.bmp");
            }
            else
            {
                goto newPath;
            }
 
Share this answer
 
i hope, this code helps you


C#
pbx_photo.Image.Save(Application.StartupPath + "\\Image\\" + cmb_id.Text + ".jpg");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900