By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,919 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,919 IT Pros & Developers. It's quick & easy.

Opening File with unknown Extension

P: n/a
Hi,
I want to open a File with unknown Extension using C#. What i want is
i do System.Diagnostics.Process.Start("FileName");
Now if File is associated with any program then the File with open
with that Application, this is working fine.

My requirement says, if file extension is unknown or not associated
with any application then, it should open the Default windows Program
association box and allow user to select a program to open that file.

Thanks.
Abhijeet Kumar.

Jun 4 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Jun 4, 10:47 pm, Abhi <Abhijeet1...@gmail.comwrote:
Hi,
I want to open a File with unknown Extension using C#. What i want is
i do System.Diagnostics.Process.Start("FileName");
Now if File is associated with any program then the File with open
with that Application, this is working fine.

My requirement says, if file extension is unknown or not associated
with any application then, it should open the Default windows Program
association box and allow user to select a program to open that file.

Thanks.
Abhijeet Kumar.
I would suggest using rundll32.exe to invoke the shell32.dll with
OpenAs_RunDLL parameter.

Try this:

try
{
ProcessStartInfo pInfo = new ProcessStartInfo(@"C:
\list.dat");
Process.Start(pInfo );
}
catch (Win32Exception ex)
{
if (ex.ErrorCode == -2147467259)
//ErrorCode for No application is associated with
the specified file for
//this operation
{
ProcessStartInfo openWithInfo = new
ProcessStartInfo(@"C:\WINDOWS\system32\rundll32.ex e");
openWithInfo .Arguments = @" C:\WINDOWS
\system32\shell32.dll, OpenAs_RunDLL .dat";
Process.Start(openWithInfo );
}
}

This woudl give you the Caution window displaying Openwith and Cancel
buttons.

Jun 4 '07 #2

P: n/a
On Jun 4, 11:09 pm, Aneesh P <anees...@gmail.comwrote:
On Jun 4, 10:47 pm, Abhi <Abhijeet1...@gmail.comwrote:
Hi,
I want to open a File with unknown Extension using C#. What i want is
i do System.Diagnostics.Process.Start("FileName");
Now if File is associated with any program then the File with open
with that Application, this is working fine.
My requirement says, if file extension is unknown or not associated
with any application then, it should open the Default windows Program
association box and allow user to select a program to open that file.
Thanks.
Abhijeet Kumar.

I would suggest using rundll32.exe to invoke the shell32.dll with
OpenAs_RunDLL parameter.

Try this:

try
{
ProcessStartInfo pInfo = new ProcessStartInfo(@"C:
\list.dat");
Process.Start(pInfo );
}
catch (Win32Exception ex)
{
if (ex.ErrorCode == -2147467259)
//ErrorCode for No application is associated with
the specified file for
//this operation
{
ProcessStartInfo openWithInfo = new
ProcessStartInfo(@"C:\WINDOWS\system32\rundll32.ex e");
openWithInfo .Arguments = @" C:\WINDOWS
\system32\shell32.dll, OpenAs_RunDLL .dat";
Process.Start(openWithInfo );
}
}

This woudl give you the Caution window displaying Openwith and Cancel
buttons.
Am assuming windows has been installed to C:\. Change the path
according to your installation drive in code or retrieve the windows
path using environment variables - %WINDIR% or %SYSTEMROOT%.

Jun 4 '07 #3

P: n/a
On Jun 4, 2:09 pm, Aneesh P <anees...@gmail.comwrote:
On Jun 4, 10:47 pm, Abhi <Abhijeet1...@gmail.comwrote:
Hi,
I want to open a File with unknown Extension using C#. What i want is
i do System.Diagnostics.Process.Start("FileName");
Now if File is associated with any program then the File with open
with that Application, this is working fine.
My requirement says, if file extension is unknown or not associated
with any application then, it should open the Default windows Program
association box and allow user to select a program to open that file.
Thanks.
Abhijeet Kumar.

I would suggest using rundll32.exe to invoke the shell32.dll with
OpenAs_RunDLL parameter.

Try this:

try
{
ProcessStartInfo pInfo = new ProcessStartInfo(@"C:
\list.dat");
Process.Start(pInfo );
}
catch (Win32Exception ex)
{
if (ex.ErrorCode == -2147467259)
//ErrorCode for No application is associated with
the specified file for
//this operation
{
ProcessStartInfo openWithInfo = new
ProcessStartInfo(@"C:\WINDOWS\system32\rundll32.ex e");
openWithInfo .Arguments = @" C:\WINDOWS
\system32\shell32.dll, OpenAs_RunDLL .dat";
Process.Start(openWithInfo );
}
}

This woudl give you the Caution window displaying Openwith and Cancel
buttons.
I tried the code given by you, it is giving me error as

---------------------------
Application Error
---------------------------
An error occurred please contact the adminstrator with the following
information:

No application is associated with the specified file for this
operation

Stack Trace:
at
System.Diagnostics.Process.StartWithShellExecuteEx (ProcessStartInfo
startInfo)

at System.Diagnostics.Process.Start()

at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)

at Wachovia.CIB.CDF.Shell.frmMain.newHelpMenuItem_Cli ck(Object
sender, EventArgs e) in c:\projects\vcs\vss\onesource 1.2 plus\client
\src\client\wachovia.cib.cdf.shell\frmmain.cs:line 3501

at
Syncfusion.Windows.Forms.Tools.XPMenus.BarItem.OnI temClicked(EventArgs
args)

at Syncfusion.Windows.Forms.Tools.XPMenus.BarItem.Per formClick()

at
Syncfusion.Windows.Forms.Tools.XPMenus.MenuGrid.No tifyItem(BarItem
item)

at
Syncfusion.Windows.Forms.Tools.XPMenus.MenuGrid.Hi dePopup(PopupCloseType
popupCloseType)

at
Syncfusion.Windows.Forms.Tools.XPMenus.MenuGrid.Pr ocessItemClick(BarItem
item)

at
Syncfusion.Windows.Forms.Tools.XPMenus.MenuGrid.On MouseUp(MouseEventArgs
e)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at Syncfusion.Windows.Forms.ScrollControl.WmMouseUp(M essage& msg)

at Syncfusion.Windows.Forms.ScrollControl.WndProc(Mes sage& msg)

at Syncfusion.Windows.Forms.Grid.GridControlBase.WndP roc(Message&
msg)

at Syncfusion.Windows.Forms.Tools.XPMenus.MenuGrid.Wn dProc(Message&
m)

at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)

at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
---------------------------
Abort Retry Ignore
---------------------------
What is OpenAs_RunDLL .dat. I am trying to open a .bak File.

regards,
Abhijeet Kumar.

Jun 4 '07 #4

P: n/a
On Jun 4, 2:09 pm, Aneesh P <anees...@gmail.comwrote:
On Jun 4, 10:47 pm, Abhi <Abhijeet1...@gmail.comwrote:
Hi,
I want to open a File with unknown Extension using C#. What i want is
i do System.Diagnostics.Process.Start("FileName");
Now if File is associated with any program then the File with open
with that Application, this is working fine.
My requirement says, if file extension is unknown or not associated
with any application then, it should open the Default windows Program
association box and allow user to select a program to open that file.
Thanks.
Abhijeet Kumar.

I would suggest using rundll32.exe to invoke the shell32.dll with
OpenAs_RunDLL parameter.

Try this:

try
{
ProcessStartInfo pInfo = new ProcessStartInfo(@"C:
\list.dat");
Process.Start(pInfo );
}
catch (Win32Exception ex)
{
if (ex.ErrorCode == -2147467259)
//ErrorCode for No application is associated with
the specified file for
//this operation
{
ProcessStartInfo openWithInfo = new
ProcessStartInfo(@"C:\WINDOWS\system32\rundll32.ex e");
openWithInfo .Arguments = @" C:\WINDOWS
\system32\shell32.dll, OpenAs_RunDLL .dat";
Process.Start(openWithInfo );
}
}

This woudl give you the Caution window displaying Openwith and Cancel
buttons.
Hi,
I restarted the System and now the error message has changed to
---------------------------
RUNDLL
---------------------------
Error in C:\WINDOWS\system32\shell32.dll
Missing entry:OpenAs_RunDLL.dat
---------------------------
OK
---------------------------

Regards,
Abhijeet.

Jun 4 '07 #5

P: n/a
Abhi <Ab**********@gmail.comwrote:

<snip>
I restarted the System and now the error message has changed to
---------------------------
RUNDLL
---------------------------
Error in C:\WINDOWS\system32\shell32.dll
Missing entry:OpenAs_RunDLL.dat
---------------------------
OK
---------------------------
Did you actually cut and past Aneesh's code? He has a space between
RunDLL and .dat - the error message you're getting *suggests* that your
code doesn't.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 4 '07 #6

P: n/a
On Jun 5, 2:23 am, Jon Skeet [C# MVP] <s...@pobox.comwrote:
Abhi <Abhijeet1...@gmail.comwrote:

<snip>
I restarted the System and now the error message has changed to
---------------------------
RUNDLL
---------------------------
Error in C:\WINDOWS\system32\shell32.dll
Missing entry:OpenAs_RunDLL.dat
---------------------------
OK
---------------------------

Did you actually cut and past Aneesh's code? He has a space between
RunDLL and .dat - the error message you're getting *suggests* that your
code doesn't.

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Exactly..while copying some formatting is lost I guess. There should
be a space between OpenAs_RunDLL and .dat which I can't see in the
error message.

Jun 5 '07 #7

P: n/a
On Jun 4, 10:48 pm, Aneesh Pulukkul <anees...@gmail.comwrote:
On Jun 5, 2:23 am, Jon Skeet [C# MVP] <s...@pobox.comwrote:


Abhi <Abhijeet1...@gmail.comwrote:
<snip>
I restarted the System and now the error message has changed to
---------------------------
RUNDLL
---------------------------
Error in C:\WINDOWS\system32\shell32.dll
Missing entry:OpenAs_RunDLL.dat
---------------------------
OK
---------------------------
Did you actually cut and past Aneesh's code? He has a space between
RunDLL and .dat - the error message you're getting *suggests* that your
code doesn't.
--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Exactly..while copying some formatting is lost I guess. There should
be a space between OpenAs_RunDLL and .dat which I can't see in the
error message.- Hide quoted text -

- Show quoted text -
That was the mistake, Its working now,

thank you.

Jun 5 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.