Creating File Extensions for my application - c#

I'm wondering how I can create my own file extension to work with my application. For example, say I wanted to have a ".abc" extension. The full file name example would be "MyFile.abc".
I want the file to behave in a way that when it is double clicked, it will open up in my application, but actually it contains data of a .xml file.
Sorry if this makes little sense, this is completely new to me. I'm using c# in visual studio 2013, and basically my application is an automatic update installer. I want it so when my file with my own extension is selected, my application opens and uses the xml data from it to do the update.

You can create your own files with custom extensions by saving the file with that particular extension. Then what you need is to associate the extension with your application. For this you need to create the instance of FileAssociationInfo .
Check this out System-File-Association

Related

custom client localization form Win Forms

I have big WinForms project,and now i need to create module,where client can create/update/delete its own localization to a project (dataGrid Name-Value,like resx files).Also we need a default localization.But in WinForms every form has own resx file=( What the best way to realize this feature?Xml file or it could be done by resx files.
In previous version of the project (unfortunately no source code) it was jsut text Key-Value file.
There are diffrent way to approch that topic. On top of my head i have 2 solutions for that problem.
First solution
Since *.resx files are compiled into executable you cannot really modify them, but since you are using them already easiest approach would be to change reference from original build in *.resx file to one you have made and put in your folder hierarchy. That way you could use your build in files as default and search for other languages if they exists replace them.
This might help you Modifying .resx file in c#
Downside of this approach is that resx files are c# classes and could be realy hard to edit outside of Visual Studio editor.
Second solution
If you have time to move all of your default texts to *.xml files you could do that and use similar approach like in *.resx file. Since i found it easier to create and edit xml files this could save your day. Downside of that approach is time required to connect every string to your windows forms app.

How to publish config files along with application in windows forms application

I have a very simple use case.
1) I have 4 config files which are needed for the application to start.
When I publish my application these files should be exported by default along with it. How can I do this ? Where should the files be stored so that they are available when the pplication is installed?
The users of this application should be able to edit and access these files.
I have seen the option of saving it using string source = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
I have tried adding these as resources, but these files need to be editable, hence cannot be in exe.(Reference is this question)
Please comment if you need additional information.
If you're building the installer in Visual Studio, you can add those files as Content and it should be automatically included in the installer when it's built.
You create installers in Visual Studio by adding a Setup Project to the solution.
Link to tutorial on MSDN: http://msdn.microsoft.com/en-us/library/vstudio/19x10e5c(v=vs.100).aspx
I recall it should automatically add all Content items automatically, but I'm a bit rusty. Here's more detail on how to add items to your installer, including desktop shortcuts and such:
http://msdn.microsoft.com/en-us/library/vstudio/z11b431t(v=vs.100).aspx
Good luck!
There are meny ways to do whay you want to do. the main question is why do you want to do it?
if you have a normal program for personal use you can simply link it to the needed file, meaning using the file without actual knowledge that it's there.
if it's for a task then you can zip them together, that way you'll know they are together, without adding them as resource.
for other kind of use, or if you have to add them as resources, just add them like shown here
for more reading on what do you need and how to do it i have here linked vs. Embeded resources
good luck

Open file on start up

I don't know what it is called but I want to be able to double click on my saved file and then my program should open and load the file. What is this called and how do I do it?
I am using c# wpf and .net 4.0
BR
How about the last 2 fields, what am I supposed to write there?
That is a file association, if you want this to happen on a client machine you need to register your application as the default application for a given extension. This question might be handy.
To actually handle the opening you need to process the arguments that are handed to your application, they will contain the file path. You can get the arguments either in the override of Application.OnStartup (e.Args) or Environment.GetCommandLineArgs.
you need to register the file extension and associate it to your program, either during the setup using certain APIs or from code when program executes the first time.
check these ones:
How to associate a file extension to the current executable in C#
Associate File Extension with Application
personally I do not like the 100% registry approach, there should be some Windows APIs for that and we should let those APIs to work without worrying about the Registry from our side, in my opinion.

End user wants to add languages dynamically to his website

We have to build an event registration website for our client in ASP.NET using C#.
One of the requirements is that the client wants to add new foreign languages to his website himself using en excel file. I know how to make a website multilingual in Visual Studio, but I have no idea how to generate a resource file based on an excel file in code.
I also noticed VS generates a second file called Resource.en.designer.cs but I can't find any documentation how to generate that file either.
btw, the enduser is anything but IT-related. He knows his way around excel though (obviously).
Any help is appreciated!
Yoeri
EDIT:
!Robert Levy Provided a good method!
HOW TO:
STEP 1:
Read the excel file (using an OleDBAdapter was the best method for me, as you can use column headers etc)
Write the language to a txt file in this format:
KEY=TRANSLATION
no spaces or anything else
STEP 2:
Locate ResGen.exe on your computer (it comes with Visual Studio, so look somewhere like c:\program files\visual studio\sdk... however I found it # C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe)
STEP 3:
Invoke the exe with Process.Start("resgen.exe")
hint: use ProcesStartInfo for easy argument and preferences settings
(STEP 4:)
Move the file to your desired location (I find the App_GlobalResources works perfectly)
STEP 5:
Set the user currentUIculture to your desired culture!
ResGen.exe will compile resource files for you. You could either get him to deliver text files in the format used by that tool or write your own code that extracts from excel to generate the text files. Then just invoke this EXE and deploy your newly generated resource DLL. I am assuming you already know how to read things from resource files and use the appropriate one based on user preference.
http://msdn.microsoft.com/en-us/library/ccec7sz1.aspx
This is probably one place where you would like to use resources from database rather than simple resx files. It would be easier just to populate database table(s) with Excel data than transforming it to standard resx file (it could be a problem in the future if MS decided to modify file format).
So I would suggest you to write your own ResourceReader which would load strings from database (it could load it directly from Excel as well, but for many reasons I wouldn't recommend this method).
You should ask your end-user if they really have to get another language 'on the fly' and how many languages they expect they are going to add.
Otherwise, e-mailing the Excel file to you and manually creating the resource file might be by far the cheapest solution....

How can I make an application open when a user double clicks on its associated file?

I am creating an application that uses a certain file format as its data source. I want this application to open whenever the user double clicks on this file, like how MS Word will open when a user double clicks on a Word document. How do I accomplish this? Also how would I populate the data fields using the file that the user selected. Would I use args[] from the program.cs class? I am using c# to code this application.
N.B. I want this association to be made when the application is installed on the host machine without the user doing anything.
FIRST, you need to set up file association, so that your file type is associated with your application and opening the file type will run your application.
You can do the file association programatically, there is some detail here as mentioned:
http://www.codeproject.com/KB/dotnet/System_File_Association.aspx
You can also do it via your Setup project for you application if you have one. This is an easier path for "newbies". Details for using visual studio to get the setup project to add the file association and also set the icon for the file are here:
http://www.dreamincode.net/forums/topic/58005-file-associations-in-visual-studio/
Otherwise if you use InnoSetup, Wix etc then I suppose you could just see instructions for those installers to create the association for you.
SECOND, you need to have your application accept command line arguments. The opened file(s) is(are) passed as a command line argument(s). You need to process the arguments to get the file path/name(s) and open the given file(s). There is a nice description of this here with code:
C# Command Line arguments problem in Release build
In your case, rather than MessageBox.Show(s) in the form shown handler, you would call your bespoke argument parsing method.
For a simple application which only accepts files names to open as arguments, this could be as simple as
foreach (string filePathName in Args)
DoNamedFileOpen(filePathName);
Your code can also have a method that might extract from the file the values for the datafields you are interested in etc.
This is a nice simple approach to the issue of have file associations set on installation of your application, with icons, and having your application handle the opening of those files.
Of course, there are plenty of other options, like run-time file association (asking the user if they want the association), detecting "broken" associations, etc.
This question is a long time here but I hope this is useful for new searches
See this. Or this if you want API information.
ClickOnce supports file associations as of .NET 3.5 SP1, too. In the project's properties, switch to the Publish tab and click the Options button. There's a File Associations section in that dialog that allows you to specify file extensions, descriptions and custom icons.
First, you have to associate the filetype extention with your executeable. On Windows you do this via the registry (search "filetype association windows"). In this question you find some interesting hints: Filetype association with application (C#) Script to associate an extension to a program
Your program has to react on the command line arguments or parameters. In Java, it is indeed the string array of the main method. I would gess, it's the same in C#.
If you don't need to do it pro programatically, right click on the icon, click open with ..., then select 'always use this program ...'.
This is something usually handled by your setup program .. I've used INNO setup for example, and it's trivially simple to arrange for it to adjust user's registry to launch your app when associated file extension is double clicked/opened. It'll even take care of MIME types for you as well as clearing these things on uninstall, which is a very nice thing to do
I managed to solve this issue. I used WIX to create an install file and asked it to associate the file with the application when it installs.

Categories

Resources