473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Opening File with unknown Extension

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
7 11635
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stefan | last post by:
Hi, I just downloaded PHP-4.3.3 for win32 and got the extensions folder and dropped it intot he root of the PHP directory and set it's path in the PHP.ini: extension_dir =...
2
by: Christian Seberino | last post by:
I have a program that has Python and C code. I added Extension stuff to setup.py and all .c and .h files get into tarball fine. (I have something like Extension("foo", glob.glob("bar/*.") ) ...
4
by: David Allison | last post by:
I am looking to open my MDE Application using the DB files associated with the application I have created. My application is using a non descript three digit extension that is related to the...
3
by: David | last post by:
Should you be able to map a any file extension to the ASP.NET dll and have it execute ASP.NET script, just like an .aspx page, when it is requested by a browser. If not, why bother giving us the...
3
by: Nate Hekman | last post by:
I have an aspx page that generates a file on the fly for a person to download. It sends these http headers: Content-Type: text/plain Content-Disposition: attachment; filename="myfile.lic" ...
18
by: Al | last post by:
I'm still trying to do this but it never worked! In a .cpp file, I write the code, and at the beginning, I write: #ifndef MYLIST_H #define MYLIST_H ....to end: #endif What's wrong with it for...
2
by: OutdoorGuy | last post by:
Greetings, I have a "newbie" question in relation to opening files from C#. I have a Windows form where I allow the user to type in a file extension in a text box (e.g., "xls"). I then take...
4
by: tasahmed | last post by:
Hello Friends, I wrote a function which scans the current working directory and lists out details such as directory/file owner, permission etc. The output of this script can be viewing in the...
2
by: dazzler | last post by:
I need to open PDF file with my python application, and I'm using os.startfile(filename.pdf) command, I would need open command act 100% like clicking the file in the windows explorer python...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.