Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've developed a console application that reads path of image file and then converts it into grayscale.
The application works fine with file path that does not contain white spaces, but fails if path contains white space.
How to rectify this?

Thanks for your time.
[no name] 23-Jan-12 6:58am    
Show how you are using the path. The API should handle whitespaces
[no name] 23-Jan-12 7:14am    
I'm using Bitmap OriginalFile = (Bitmap)Image.FromFile(filepath);

Assuming your path is something like C:\Users\Nikhil\My Documents\filename.jpg then your command should be:
program "C:\Users\Nikhil\My Documents\filename.jpg"

Note the quote characters around the path.
Share this answer
Sergey Alexandrovich Kryukov 23-Jan-12 23:44pm    
Sure, a 5.
May be this will help,

string path= @"File Path";
path= path.Replace(" " , "");

and there is also a good method in C#, String.Trim()


but Trim will removes all whitespace characters from the start and the end of the string but
Share this answer
[no name] 23-Jan-12 7:10am    
Thanks, this solution worked, but i only used string path= @"File Path";

wondering what is @ and why to replace " " with ""?
AmitGajjar 23-Jan-12 7:12am    
@ is used for ignoring escape characters.

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