how can i start any application from C#
i mean for example, if i have an openfiledialog and the user opened it and selected any file and opened it, i need this file to opened in its application whatever its extension and its default start application.
i have googled and found that Process.Start takes the file name and its application but i don't know what is the type of the file the user is going o open
thanks in advance for any replies.
Process.Start has several overloads; you want the one that takes only a string. From MSDN:
It can be of any file type for which the extension has been associated with an application installed on the system. For example the file name can have a .txt extension if you have associated text files with an editor, such as Notepad, or it can have a .doc if you have associated .doc files with a word processing tool, such as Microsoft Word.
Example:
Process.Start(myOpenFileDialog.FileName);
You can call Process.Start with any filename and the file will open in its default program.
Related
Smart people in the world. Anyone knows.. Can WPF desktop application manages to open a local file in its default open software. To give an example, when i clicks a .doc file in my WPF desktop application, Microsoft Word should open such a file
Simply use Process.Start and pass the file name. This has nothing to do with WPF.
So I'm using WebClient to upload a file to a server. It works great except for one problem. If the file is opened by another program then it will not upload. For instance, if it's a word document that's been saved but is still opened by word then it fails to upload. Is there a way to force it to read whatever is there and upload it?
If i understand your question right then you can use this solution to test if the file is open and then close it if it is. It's a useful helper class i've used in the past.
https://stackoverflow.com/a/1247326/4612655
In my console application, I am generating some .pdf files and putting them in a specific folder. Each of these files have unique content with unique names. For example, a similar file names is "6cc32a23-321d-3v8ba181-aa4c38cd7e3a.pdf".
What I would like to do, is open these allow the user to open the pdf from within the console application. Of course they could navigate to the folder they are stored in each time, but I don't wan to do that.
Because the name of each file is unique, how can know which file to open? I had the thought of created a method that searches the folder based on the newest "Date modified". The method basically search the folder for the newest file and attempt to open it. Is that even possible? Any other suggestions would be helpful as well. Thanks!
I am create an .xls file programatically and opening it in excel
for example:
Process.Start("c:/blabla.xls");
I am deleting the file when excel is closed, so I would like to prompt the user if he wants to save the file when excel before it is closed, and ideally make him save it to a new location.
I'm hoping there is an argument I can feed to excel during the Process.Start
Instead of opening Excel with an Excel file (.xls), you could open Excel with a Excel template (.xlt). This should open a new, unnamed file in Excel, using your xlt as the template. Since the file is unnamed, the user will be prompted to choose a location and file name if he made any changes.
(I'm not sure if renaming the file suffices; you might have to save the file as a template.)
EDIT: In fact, there is a command-line switch lets you do exactly that (open a normal Excel file as a template):
excel.exe /t C:\blabla.xls
Handle the BeforeClosed event.
This is assuming you are using Excel automation. Which, after reading your question again it appears you are not.
http://j-walk.com/ss/excel/tips/tip78.htm
I need help in how to create a custom file extension in my C# app. I created a basic notes management app. Right now I'm saving my notes as .rtf (note1.rtf). I want to be able to create a file extension that only my app understands (like, note.not, maybe)
As a deployment point, you should note that ClickOnce supports file extensions (as long as it isn't in "online only" mode). This makes it a breeze to configure the system to recognise new file extensions.
You can find this in project properties -> Publish -> Options -> File Associations in VS2008. If you don't have VS2008 you can also do it manually, but it isn't fun.
File extensions are an arbitrary choice for your formats, and it's only really dependent on your application registering a certain file extension as a file of a certain type in Windows, upon installation.
Coming up with your own file format usually means you save that format using a format that only your application can parse. It can either be in plain text or binary, and it can even use XML or whatever format, the point is your app should be able to parse it easily.
There are two possible interpretations of your question:
What should be the file format of my documents?
You are saving currently your notes in the RTF format. No matter what file name extension you choose to save them as, any application that understands the RTF format will be able to open your notes, as long as the user knows that it's in RTF and points that app to that file.
If you want to save your documents in a custom file format, so that other applications cannot read them. you need to come up with code that takes the RTF stream produced by the Rich Edit control (I assume that's what you use as editor in your app) and serializes it in a binary stream using your own format.
I personally would not consider this worth the effort...
What is the file name extension of my documents
You are currently saving your documents in RTF format with .rtf file name extension. Other applications are associated with that file extension, so double-clicking on such file in Windows Explorer opens that application instead of your.
If you want to be able to double click your file in Windows Explorer and open your app, you need to change the file name extension you are using AND create the proper association for that extension.
The file extension associations are defined by entries in the registry. You can create these per-machine (in HKLM\Software\Classes) or per-user (in HKCU\Software\Classes), though per-machine is the most common case. For more details about the actual registry entries and links to MSDN documentation and samples, check my answer to this SO question on Vista document icon associations.
I think it's a matter of create the right registry values,
or check this codeproject's article
You can save file with whatever extension you want, just put it in file name when saving file.
I sense that your problem is "How I can save file in something other than RTF?". You'll have to invent your own format, but you actually do not want that. You still can save RTF into file named mynote.not.
I would advise you to keep using format which is readable from other programs. Your users will be thankful once they want to do something with their notes which is not supported by your program.