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.