Click here to Skip to main content
15,909,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C# help

friends i need help for my C# simple project.when i'm saving my image i used this direct path.but when i change this project folder that path also needed to be change.
can u guys suggest good way to implement this?

pictureBox3.Image.Save(@"C:\Users\Thilan\Desktop\Our Project\OtsuThreshold1.2\Images\test2.jpg", ImageFormat.Jpeg);
Posted
Updated 9-Jun-13 21:30pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Jun-13 3:22am    
Implement what?
—SA

You should use Server.MapPath Method[^] to map the folder path.
Try this:
C#
String FilePath;
FilePath = Server.MapPath("~/Images/test2.jpg");
pictureBox3.Image.Save(FilePath, ImageFormat.Jpeg);


Please see : ASP.NET MapPath[^]


[Edit 1]

You can use :
C#
string FilePath= Application.StartupPath + "\\Images\\test2.jpg";
pictureBox3.Image.Save(FilePath, ImageFormat.Jpeg);

Also you can use : Path.GetDirectoryName Method[^]

--Amit
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 10-Jun-13 3:23am    
What tells you that the question is about ASP.NET? It looks like a question about... nothing.
—SA
Thilantdm 10-Jun-13 3:25am    
it is C# i post it also
_Amy 10-Jun-13 3:34am    
Please see the modified answer. :)
_Amy 10-Jun-13 3:33am    
I've edited the solution according to the C# tag(Probably Winforms). Please check it. :)
Thilantdm 10-Jun-13 4:19am    
thnkz friend
The Solution 1 is only good for System.Windows.Forms, as it uses System.Windows.Forms.Application, which is already not good enough, even if "Forms" tag was used in the question. There are different other ways to find out this path, and some are also not universal as they depend on how the application is hosted (it may make it unsuitable for, for example, Windows Services).

This solution I described in my past answer does not have those disadvantages:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

—SA
 
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