473,386 Members | 1,602 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,386 software developers and data experts.

"Open with" question

Hi,
I have small project which opens text files via inside the project but
i want to associate this app for every text file. To have a test, if i
right click on a text file -then "open with" -my application...
but my app's text area(textbox,where the text data is loaded into. )
is opened blank, nothing is displayed except a general view of my
project app

How can i make "open with" association to display text with my project
properly?

Thanks.
Dec 18 '07 #1
12 1396
On Dec 18, 1:38 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
Hi,
I have small project which opens text files via inside the project but
i want to associate this app for every text file. To have a test, if i
right click on a text file -then "open with" -my application...
but my app's text area(textbox,where the text data is loaded into. )
is opened blank, nothing is displayed except a general view of my
project app

How can i make "open with" association to display text with my project
properly?
All an "open with" association does is launch the associated
application with the complete path to the file clicked on in the
Command Line. It is up to your application to see that there is a file
name in the command line and process it appropriately.
Dec 18 '07 #2
>How can i make "open with" association to display text with my project
>properly?
Your application would likely accept the path to the file on the
command line. You then parse the command line during application
startup, load the file and display the content in the text box.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 18 '07 #3
On Dec 18, 9:12 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
How can i make "open with" association to display text with my project
properly?

Your application would likely accept the path to the file on the
command line. You then parse the command line during application
startup, load the file and display the content in the text box.

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
My app is not a console application however, where and what can i add
this to create a "open with" functionality?
Dec 18 '07 #4
On Dec 18, 2:37 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Dec 18, 9:12 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
>How can i make "open with" association to display text with my project
>properly?
Your application would likely accept the path to the file on the
command line. You then parse the command line during application
startup, load the file and display the content in the text box.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.

My app is not a console application however, where and what can i add
this to create a "open with" functionality?
If the form's Load event. Check the contents of the
Environment.CommandLine. If there is a filename present, open it, read
the data, and put the data in the textbox's Text property.

Dec 18 '07 #5
>My app is not a console application however, where and what can i add
>this to create a "open with" functionality?
The principle is the same in a Windows app. You can still have a
parameterized Main entry point, or you can use
System.Environment.GetCommandLineArgs() from anywhere in your code.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 18 '07 #6
On Dec 18, 9:55 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
My app is not a console application however, where and what can i add
this to create a "open with" functionality?

The principle is the same in a Windows app. You can still have a
parameterized Main entry point, or you can use
System.Environment.GetCommandLineArgs() from anywhere in your code.

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
Hi again, could you sample some code and will i put them in form_load
event?

Assume, i have a textbox and openfiledialog control and i use
streamreader to display texts.

Thanks.
Dec 18 '07 #7


"kimiraikkonen" wrote:
On Dec 18, 9:55 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
>My app is not a console application however, where and what can i add
>this to create a "open with" functionality?
The principle is the same in a Windows app. You can still have a
parameterized Main entry point, or you can use
System.Environment.GetCommandLineArgs() from anywhere in your code.

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.

Hi again, could you sample some code and will i put them in form_load
event?

Assume, i have a textbox and openfiledialog control and i use
streamreader to display texts.

Thanks.
I believe all you need to do is this:

Dim arguments As string() = Environment.GetCommandLineArgs()
Dim fn as string = arguments(0)

if (System.IO.File.Exists(fn)) then
MyTextBox.Text = System.IO.File.ReadAllText(fn)
endif

Dec 18 '07 #8
On Dec 19, 12:46 am, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
"kimiraikkonen" wrote:
On Dec 18, 9:55 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
My app is not a console application however, where and what can i add
this to create a "open with" functionality?
The principle is the same in a Windows app. You can still have a
parameterized Main entry point, or you can use
System.Environment.GetCommandLineArgs() from anywhere in your code.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
Hi again, could you sample some code and will i put them in form_load
event?
Assume, i have a textbox and openfiledialog control and i use
streamreader to display texts.
Thanks.

I believe all you need to do is this:

Dim arguments As string() = Environment.GetCommandLineArgs()
Dim fn as string = arguments(0)

if (System.IO.File.Exists(fn)) then
MyTextBox.Text = System.IO.File.ReadAllText(fn)
endif
Hi, that doesn't work :-( Only "MZ" is displayed textbox with no sense.
Dec 18 '07 #9
"kimiraikkonen" <ki*************@gmail.comschrieb:
>Dim arguments As string() = Environment.GetCommandLineArgs()
Dim fn as string = arguments(0)
.... should read:

\\\
If Arguments.Length 1 Then
Dim fn As String = Arguments(1)
if (System.IO.File.Exists(fn)) then
MyTextBox.Text = System.IO.File.ReadAllText(fn)
endif
End If
///
>Hi, that doesn't work :-( Only "MZ" is displayed textbox with
no sense.
The first argument ('Arguments(0)') seems to contain the path to your
executable file. 'MZ' are typically the first characters in executable
files.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Dec 18 '07 #10


"Herfried K. Wagner [MVP]" wrote:
"kimiraikkonen" <ki*************@gmail.comschrieb:
Dim arguments As string() = Environment.GetCommandLineArgs()
Dim fn as string = arguments(0)

.... should read:

\\\
If Arguments.Length 1 Then
Dim fn As String = Arguments(1)
if (System.IO.File.Exists(fn)) then
MyTextBox.Text = System.IO.File.ReadAllText(fn)
endif

End If
///
Hi, that doesn't work :-( Only "MZ" is displayed textbox with
no sense.

The first argument ('Arguments(0)') seems to contain the path to your
executable file. 'MZ' are typically the first characters in executable
files.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks Herfried. I wasy typing without a compiler. I believe the command
args are starting at index of one as you said.

>
Dec 19 '07 #11
On Dec 19, 3:42 am, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
"Herfried K. Wagner [MVP]" wrote:
"kimiraikkonen" <kimiraikkone...@gmail.comschrieb:
>Dim arguments As string() = Environment.GetCommandLineArgs()
>Dim fn as string = arguments(0)
.... should read:
\\\
If Arguments.Length 1 Then
Dim fn As String = Arguments(1)
if (System.IO.File.Exists(fn)) then
MyTextBox.Text = System.IO.File.ReadAllText(fn)
endif
End If
///
>Hi, that doesn't work :-( Only "MZ" is displayed textbox with
no sense.
The first argument ('Arguments(0)') seems to contain the path to your
executable file. 'MZ' are typically the first characters in executable
files.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Thanks Herfried. I wasy typing without a compiler. I believe the command
args are starting at index of one as you said.

Hi there,
After trying to figure out where and what the codes are used for i
managed to what i was trying to by adding to form_load event:

Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length 1 Then
myStreamReader = System.IO.File.OpenText(cla(1))
TextBox1.Text = myStreamReader.ReadToEnd
myStreamReader.Dispose()

'After text is opened, all the texts come up as selected, thus i added
to make them unselected.
TextBox1.SelectionStart = 0
End If

Dec 19 '07 #12
On Dec 19, 1:28 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comschrieb:
Dim arguments As string() = Environment.GetCommandLineArgs()
Dim fn as string = arguments(0)

... should read:

\\\
If Arguments.Length 1 Then
Dim fn As String = Arguments(1)
if (System.IO.File.Exists(fn)) then
MyTextBox.Text = System.IO.File.ReadAllText(fn)
endif

End If
///
Hi, that doesn't work :-( Only "MZ" is displayed textbox with
no sense.

The first argument ('Arguments(0)') seems to contain the path to your
executable file. 'MZ' are typically the first characters in executable
files.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Hi,
I want to ask this:

Why was i forced to use:

If Arguments.Length 1 Then
Dim fn As String = Arguments(1)

'do stuff

end if

For example when i want to display the current app's path:

Dim cla As String() = Environment.GetCommandLineArgs()

Msgbox(cla(0))

shows "exact" path in messagebox, no other extra or unwanted strings
like "MZ", so it would be kind of you explaining this issue.

Thanks.
Dec 25 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Bedford | last post by:
I've a textarea and would like to save the content in a mysql table each time a user click on a form. How can I do for avoiding error when the user put a " or a ' in the message, or any other...
1
by: Hale | last post by:
Hi I'm trying to connect to my oracle install using sqlplus and create a new user. I get the error "database not open". How do I open this? I'm using Oracle 9i Enterprise Edition on Linux...
1
by: Steve Jorgensen | last post by:
I know some of you here were following involved with, or annoyed with the volume of traffic in the recent thread I started called "Open Question...". I'm posting this message because, though I...
5
by: Mr Gordonz | last post by:
Hi all, I want to put a button on a page, and when the user clicks it, the standard Windows "Open File" dialogue box opens, and the user can browse/select a file on their PC. Having selected a...
8
by: Seth Darr | last post by:
I'm working on migrating an Classic ASP/VB6 COM application from an NT Server with IIS<6 to an virtual machine running Windows Server 2003 and IIS 6. I've worked through most of the obvious...
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...
1
by: kbarrios | last post by:
Hi, I am working with VBScript and I put a "window.open" inside a "form action post" due that I am handing a "checkbox" on it, but the "window.open" doesn't work: <FORM...
4
by: arajunk | last post by:
In Firefox this opens a full size window (maximized) . In IE it opens the partial window requiring user to click restore (upper right) to maximize. What am I missing ? var...
0
by: Ofelia | last post by:
Hi, I'm new to this forum and to Perl language but I would like to ask for your help. I'm working in Linux and the files I need to process are in the format “file.gz”. I created a script which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.