Click here to Skip to main content
15,936,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a image viewer windows application.I want that when i double click on a image file then it should be open with my application.
Posted
Comments
[no name] 6-May-13 13:42pm    
You would need to set the file association.
ZurdoDev 6-May-13 14:00pm    
As mentioned, you have to set the file association but there is nothing to prevent the user from changing that association.

Please see the comments to the question: you need to set file associations. If you need to do it programmatically, please see, for example, this CodeProject article: System File Association[^].

See also:
http://mel-green.com/2009/04/c-set-file-type-association/[^],
http://www.java2s.com/Code/CSharp/Development-Class/RegistryFileAssociation.htm[^].

—SA
 
Share this answer
 
Very easy method
Add ur associations type into File type editor while deploying set up
 
Share this answer
 
You can raise the DoubleClick event if you are displaying the data in DataGrid and write the view code inside

C#
//write connection to server
try
{
    if (dataGridView1.RowCount > 0)
    {
        DataGridViewRow row = dataGridView1.CurrentCell.OwningRow;
        document_type = row.Cells[7].Value.ToString();
        tag11 = row.Cells[1].Value.ToString();
        tag22 = row.Cells[2].Value.ToString();
        tag33 = row.Cells[3].Value.ToString();
        tag44 = row.Cells[4].Value.ToString();
        date1 = row.Cells[8].Value.ToString();

    }

    if (dataGridView2.RowCount > 0)
    {
        DataGridViewRow row = dataGridView1.CurrentCell.OwningRow;
        document_type = row.Cells[7].Value.ToString();
    }

    if (
        document_type == "Image"
        || document_type == "Pdf Document"
        || document_type == "Audio"
        || document_type == "Video"
        || document_type == "Text"
    )
    {
        DocumentView view = new DocumentView(documentname);
        view.ShowDialog();
        view_count();
    }
    else
    {
        int lng = Application.ExecutablePath.Length; ;
        int lng2 = lng - 18;
        string pth = Application.ExecutablePath.Substring(0, lng2);
        string destinationfolder = pth + "Documents";
        string save_path1 = destinationfolder + @"\" + documentname;
        System.Diagnostics.Process.Start(save_path1);
    }
}
catch (Exception e3)
{
    int lng = Application.ExecutablePath.Length; ;
    int lng2 = lng - 18;
    string pth = Application.ExecutablePath.Substring(0, lng2);
    string destinationfolder = pth + "Documents";
    string save_path1 = destinationfolder + @"\" + documentname;
    MessageBox.Show("System Or Windows can not open the Selected Document");
    System.IO.StreamReader sr = new
    System.IO.StreamReader(save_path1);
    MessageBox.Show(sr.ReadToEnd());
    sr.Close();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900