How can i make "open with" association to display text with my project
properly?
Thanks.
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.
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.
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.
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.
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.
"kimiraikkonen" wrote:
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.
... 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/>
"Herfried K. Wagner [MVP]" wrote:
> "kimiraikkonen" <kimirai...@gmail.com> schrieb:
> >> 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
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.