我正在创建Process类的实例,并将StartInfo.FileName路径传递给MS Paint,并作为文件的参数路径:
Process paint = new Process();
paint.StartInfo.FileName = @"C:\Windows\System32\mspaint.exe";
SchemaPath = @"E:\directory\Alisa\0-01\0-01 (1).jpg";
Console.WriteLine(SchemaPath);
paint.StartInfo.Arguments = SchemaPath;
paint.Start();
我的问题是 - 当我的文件名包含空格时,mspaint完全忽略该文件并抛出错误。例如,当我的文件有路径时:
E:\directory\Alisa\0-01\0-01abc.jpg
一切正常,但当我有路径文件时:
E:\directory\Alisa\0-01\0-01 (1).jpg
Paint打开但会抛出消息:
E:\directory\Alisa\0-01\0-01.png was not found.
有谁知道如何处理它?</ p>
答案 0 :(得分:2)
尝试引用类似
的路径paint.StartInfo.Arguments = string.Format("\"{0}\"", SchemaPath);
答案 1 :(得分:0)
fname.Replace(@" ", "");
使用上述方法,您可以在处理之前替换空间
Process paint = new Process();
string fname = @"C:\ Windows\System32\mspaint.exe";
string k = fname.Replace(@" ", "");
paint.StartInfo.FileName =k;
Console.WriteLine(SchemaPath);
paint.StartInfo.Arguments = SchemaPath;
paint.Start();
答案 2 :(得分:0)
Dim bmpFile As String = "C:\Users\Public\ScreenShot.jpg"
Using BMP As New Bitmap(AxAcroPDF1.Width - 20, AxAcroPDF1.Height) '20 IS ATTEMPT TO CLIP OFF THE SCROLL BAR.
Using G As Graphics = Graphics.FromImage(BMP)
G.CopyFromScreen(0, 0, 0, 0, BMP.Size)
BMP.Save(bmpFile, Imaging.ImageFormat.Jpeg)
End Using
End Using
Shell("cmd /c mspaint /p " & bmpFile) 'WORKS!