|
Enclose the entire path to all filepaths, even your winword.exe, in double quotes. Your command line would end up looking like this:
"C:\Program Files (x86)\Microsoft Office\Office14\WinWord.exe" "C:\Users\xxxx\Documents\Visual Studio 2010\...\01SettingsForVSC#.doc"
The quotes MUST be part of the string, otherwise any spaces in the path will deliniate a parameter for the command line.
|
|
|
|
|
It worked... THANK YOU Dave !!!
string MSWordPath = "\"c:\\Program Files (x86)\\Microsoft Office\\Office14\\WINWORD.EXE\"";
selectedFile = "\"" + path + "\\" + listBox1.SelectedItem as string + "\"";
Process.Start("WINWORD.EXE", selectedFile);
|
|
|
|
|
Assuming Word is installed and is the default app to process .doc files, there is a much simpler alternative:
Process.Start(myDocFilePath);
This is equivalent to double-clicking "myDocFilePath" inside Windows Explorer, it doesn't care about spaces, and it doesn't need to know where your Word app is and what it is actually called.
BTW: what you wrote earlier, then removed, wasn't correct; a partial success is not a proof of correctness!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes I know, that putting only the fileName+path, that file is opening with the default app.
But what I really want is to open a html file and edit it with msword.
If you have other alternative than: Process.Start(myDocFilePath); please tell.
Though, thank you for your fast response...
|
|
|
|
|
Editing an HTML file with Word is a horrible idea. When saved, the resulting HTML file will be all but useless to a website as Word adds TONS of crap to the file that just hoses up everything. CP gets a fair number of articles posted that were written in Word and saved in HTML format. You should see the carnage that ensues.
|
|
|
|
|
yes ) I know that too "Word adds TONS of crap to the resulting HTML".
But i dont make it for publication, just for my inner use. So, Ill adapt to its creepiness.
If are some hints to make something look good/and right editing with msword, please do tell.
thanks.
|
|
|
|
|
There is no way to get Word to stop screwing up your HTML.
|
|
|
|
|
Dave Kreskowiak wrote: There is no way to get Work to stop screwing up your HTML.
Darn coworkers!
|
|
|
|
|
|
If you want to go against the established file associations, then you need to specify the executable as the first parameter to Process.Start, the arguments concatenated and properly quoted as the second parameter. You already have that.
Using Word for HTML editing is a horrible idea. Type three words and you get a huge file, that should tell enough. Use a real HTML editor, or use Visual Studio, or whatever you choose, but not Word.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
You know, (you deleted what you originally replied with!) just because it worked with Notepad before does NOT mean that you did it correctly.
Even in this latest code, I can see HUGE problems with it. You're code is making some rather large assumptions that will break it if run on another system that isn't identically configured with the exact Office installed in the exact same way it is on your machine.
|
|
|
|
|
I am certain that you guys are right, but for the moment i want to make MY OWN HELPING FRIENDS APPs.
After that, I will make app for distribution, though i wonder if i will really do that.
|
|
|
|
|
It's up the the particular application to interpret the command line in any way it chooses. Notepad is unusual in that it does not require a path containing spaces to be quoted. This is probably because Notepad can take one argument, a filename, and it has been coded to accept spaces within the name. Word has many command line options http://support.microsoft.com/kb/210565[^]and requires that filenames containing spaces are quoted to ensure that they are recognised as one item.
The executable path passed to the Process.Start method does not need quoting as it can only ever refer to one file.
Alan.
|
|
|
|
|
I see a little problem with saving from msWord back to original.
The file is opened all right, but in read-only.
How do I change this?
Sorry for my lack of knowledge... but this things are a bit new to me.
|
|
|
|
|
Do the user under which is running your program have write privileges over the file?
Can you open it by hand (eg. open Word and then open the html file) and save it?
|
|
|
|
|
Yes, If I open it by hand, it is saving ok, loading ok... I am the only user and I have all the privileges over the file R&W.
|
|
|
|
|
Does your app (that contains the Process.Start stuff) do something else with the same .doc path, something Stream-like, File-like, FileInfo-like? If so, did you Close() and Dispose() it properly before calling Process.Start()?
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes, it opened the file... and I was not disposed it. Now is working correct.
Thank you.
|
|
|
|
|
I'm trying to get a WCF service up and running inside a Windows Service. The WCF service is supposed to troll for messages (xml) in a queue, adapt the xml message body to one of our business objects, and toss the object down the architecture as if it were just any other <insert>.
I worked through the installation earlier this morning (wasn't running command line as Administrator...remember to do that lol) but now, when I attempt to start my service, it pops up and gives the familiar
<Foo> service on <machine> started and then stopped. Some services stop automagically if they are not in use by other services or programs.
I don't think I'm doing anything fancy, at all. I'm just trying to get the thing to fire up and possibly see a message dropped on the queue get picked up by our WCF service, adapted, and inserted into our database.
I'm not really all that experienced with WCF services though...and come to think of it, I don't think I've actually created a Windows Service since college...and it seems as if Google does not know this answer or I'm phrasing my searches incorrectly.
Here's my Windows Service code.
public partial class LoggingWinService : ServiceBase
{
public ServiceHost host = null;
public LoggingWinService()
{
ServiceName = "LoggingServiceSample";
InitializeComponent();
}
public static void Main()
{
ServiceBase.Run(new LoggingWinService());
}
protected override void OnStart(string[] args)
{
if (host != null)
{
host.Close();
}
host = new ServiceHost(typeof(LoggingWCFService));
host.Open();
}
protected override void OnStop()
{
if (host != null)
{
host.Close();
host = null;
}
}
}
...help?
"I need build Skynet. Plz send code"
modified on Friday, May 20, 2011 12:07 PM
|
|
|
|
|
...hmmm. Seems I jumped the gun a bit on throwing up a flag asking for help. I had checked the Application Logs in the EventViewer for information, saw nothing reported for my service, and continued digging elsewhere for a solution. Apparently, I had read the logs incorrectly and erroneously dismissed them in my process. Although I'm not completely up and running yet (have yet to test the queue feed), it seems as if my initial problem was due to my accidental decoration of an endpoint with a behavior when I intended that behavior to tag the service itself.
Upon further investigation, pulled the following from Application Log in the EventViewer:
Service cannot be started. System.Configuration.ConfigurationErrorsException: There is no endpoint behavior named 'metadataBehavior'.
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at ...
(metadataBehavior is a service behavior, not an endpoint behavior)
"I need build Skynet. Plz send code"
|
|
|
|
|
Hi ,
I have an application to split images using c#. The problem im facing is that i need the images to be compressed and saved to .ica readable format. I have tried most of the common compression types and have not succeeded.
Any help would be appreciated. Thanks
|
|
|
|
|
ICA is an image format Citrix came up with and stands for Independent Computer Architecture.
I don't know of any libraries that will convert an image to this format. You may have to get with Citrix to see if they have something to help you.
|
|
|
|
|
Hello
How can i create one button for two events?
For example: I want to have one button for start/stop.
At the beginning of the application button name is start (start the event ), when I click the button second time it change the name to Stop (stop the event)????
I am very new to C# programming, i know to do this in VB6... Sorry for my bad english!
ThankYou
|
|
|
|
|
You can just create 2 event handlers one called Stop, the other Start and just swop between the 2, something like this
void Stop(object sender, RoutedEventArgs e)
{
button1.Click -= new RoutedEventHandler(Stop);
button1.Click += new RoutedEventHandler(Start);
button1.Content = "Start";
}
void Start(object sender, RoutedEventArgs e)
{
button1.Click -= new RoutedEventHandler(Start);
button1.Click += new RoutedEventHandler(Stop);
button1.Content = "Stop";
}
Initially the Click event would be set to Start().
Hope this helps
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Ok understand that. But now i have problem to call this voids in
private void btnstart_Click(object sender, EventArgs e)
{
if (button1.Content = "Start")
{
}
else
{
}
}
I get error:The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?)
|
|
|
|