last day (14 days later) » 

2:37 AM
1
A: manipulate a string for opening word document C#

Grant WinneyTry surrounding the file name in quotes as well: _p.StartInfo.Arguments = string.Format("\"{0}\"", lbFiles.SelectedItem); Also, Word.exe doesn't work on my system. You may need to change that to: _p.StartInfo.FileName = "WinWord.exe"

 
An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll Additional information: Cannot start process because a file name has not been provided.
 
I'll try it out myself and see if I get the same thing. Try placing a break point on that line and see what the value of SelectedItem is, just to make sure it's got the file name in it.
 
"\"C:\\Users\\User\\Desktop\\New Microsoft Word Document.docx\""
 
This works on my system. Try changing the file name from "Word.exe" to "WinWord.exe" as well. It might be that it can't find the correct program to start, in order to display the document.
 
this is the result I get ( with your solution )
I take the _p.StartInfo.FileName - from registry based on this post
so WinWord.exe is not relevant but the path string should be some way to manipulate it
 
2:37 AM
I gotta ask, you're absolutely sure the file exists? If you paste the value "C:\Users\User\Desktop\New Microsoft Word Document.docx" (including the quotes) into your start menu / run box, or into a command prompt, does it open the file? You've got a user account on your system that's literally named "User"?
 
positive 100% it gets to the list from open file dialog. also it breaks the name of the file and tries to search for each part.like new.doc microsoft.doc etc ... each space is a different search
Also it works for New Text Document.txt and it's opened automatically in the notepad ( as defined by the registry ) as I said it's strange and it occurs only with WORD.
 
Humor me and try "WinWord.exe", temporarily. Just curious, any difference? Or same situation? Trying to open each part is what I'd expect by default, but not once you surround it in quotes using the above code.
 
I'll humor you more then you think, tried "WinWord.exe" - worked !! after changed back to the registry - Worked also :)
 
That's just weird! I wonder if somehow, even after changing, it wasn't recompiling for you or something. Anyway, that's good.
 
I think I just had a mistake in the systax ( logical one )
otherwise , don't know how to explain it ...
 
2:38 AM
Ah. Could've been. Then it was using the last successful build without you realizing it. That's happened to me before.
 
well, I did built it before running...
 
I don't know then. Chalk it up to some inexplicable behavior, I guess? :)
 
by the way , is there an expression for this @"string" and to apply it on a string with symbols ?
 
I usually call it "verbatim"
The @ symbol, that is
I guess the whole string would be a verbatim string, or string literal
 
2:57 AM
WoW - interesting info !!
in any case !! THANKS !!! it helped me a lot ( of course I'll try to do it with string Literal ) if I'll understand how it works, !! and Thanks again !!
 
No problem, you're welcome!
 

last day (14 days later) »