|
The filename is passed as a parameter into your program, so your static void main should take a string[] as a parameter, and it's in there.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
can you please give more specifics, i have seen that before, but i don't know how to get the filename from using that. Please give some code example, i am a noob and have only been coding for a few months.
Say it takes the parameters string[] args. When i tell it to open the file from the filename args[0], it throws an error.
|
|
|
|
|
TheBirdman99 wrote: When i tell it to open the file from the filename args[0], it throws an error.
Verify that the filename is being passed through, then check the error. Start with a messagebox to show the values in the array, then you know what you're working with.
What error ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
the error was from the try and catch open metheod. it tries to open the file from the specified filename and then make the rich text box's rtf the same as the files.
i used a for loop to show a message box for each part of string[] args. it showed the file path, but it was split up into four different message boxes. is there a way to combine them all to one string to get the complete path?
i tried using a new string as the full path, but when i use += for each part, the location of "Documents and Settings" becomes "DocumentsandSettings" with no spaces because they were in differnt parts of the array.
|
|
|
|
|
You can use Path.Combine ( in System.IO ) to combine all the strings, but you have to do it a pair at a time.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
thank you so much!! i got it to finally work. i realized that the message boxes broke at every space, so i told it to add a space after each part like this.
static void Main(string[] args)
{
string fullFileName = "";
for (int i = 0; i < args.Length; i++)
{
fullFileName += args[i] + " ";
}
Application.Run(new Form1(fullFileName));
}
|
|
|
|
|
Sorry, but this is wrong.
You must tell Windows to pass the entire path name as one object;
whatever else you try will take unnecessary code, that will eventually fail on
special cases (e.g. a path containing two consecutive spaces).
The easiest way is to specify "%1" rather than %1 in the registry entries that you
created to link the file extension (or the Explorers "open with myApp" menu item) to your app.
After doing so, Environment.GetCommandLineArgs[1] will yield the complete file spec
of the first file you double clicked or selected for "open with myApp".
Luc Pattyn
|
|
|
|
|
alright, so i changed %1 to "%1" instead, but can you please tell me why the compiler wont let me do:
string fullFileName = Environment.GetCommandLineArgs[1];
it says
" Error 1 Cannot apply indexing with [] to an expression of type 'method group' "
|
|
|
|
|
i did this instead:
string[] temp = Environment.GetCommandLineArgs();
string fullFileName = temp[0];
it seems to work on double clicking a document and opens a blank one like it should when the .exe file is opened. However, when i run it in debug mode in visual C# 2005 express, it opens the vshost.exe and the text of the document becomes "MZ". is this natural, and also, am i doing everything you said correctly? thanks for your help.
|
|
|
|
|
Yes, you should ignore the string at index 0, since that is pointing to your exe
(indeed, with .vshost inserted in case of Studio 8.0);
so your file name(s) is/are at indexes 1 upwards.
Luc Pattyn
|
|
|
|
|
Sorry, my mistake should be Environment.GetCommandLineArgs()[1]
Environment.GetCommandLineArgs is a method that returns a string array, and you
probably want (at least) the element with index 1.
Regards.
Luc Pattyn
|
|
|
|
|
when i use the index of [1] my computer freezes and visual c# tells me that the error was because [1] was outside of the bounds of the array.
i just built it instead of ran debug and double clicking on a document works fine, but once again, when ran in debug, the same error came up, so should i put an if statement to check the length of the array?
|
|
|
|
|
OK, here is the full story:
execute
string[] args=Environment.GetCommandLineArgs();
and you will get a string array with at least 1 element.
Ignore args[0], it is the path of the exe itself (with the vshost remark).
If you started without anything special, there wont be any more args.
If you somehow specify a command line with real arguments, then the array args will hold
more elements, they each represent a real argument, such as
file paths entered thanks to the "%1", but it could be other things, e.g.
when you start from inside a DOS console, or you use the Visual textbox that lets
you specify command line arguments. So you may need your own command line conventions,
maybe you want to support switches starting with a slash and/or starting with a minus, etc.
This should get you going...
Luc Pattyn
|
|
|
|
|
Thanks for all the help Christian Graus and Luc Pattyn. I really apreaciate it!
|
|
|
|
|
I have got a software package from company with some .dll files in bin folder of the software.
How can I view those .dll files in Visual Studio editor? If someone can help me that would be great.
Haseeb
|
|
|
|
|
helpfulguy wrote: How can I view those .dll files in Visual Studio editor?
Drag and drop the DLL onto the Visual Studio window. However, you won't get to see much. Just some version information.
A much better tool is Lutz Roeder's Reflector[^]. It will take a .NET dll and reverse engineer it so you can see something that looks similar to the original code.
|
|
|
|
|
Thanks man!!!!
also can I ask one more thing:
what book do you recommend to learn C# 100% and how much time do I need to master it?
Haseeb;)
|
|
|
|
|
helpfulguy wrote: what book do you recommend to learn C# 100% and how much time do I need to master it?
If by C# you include the .NET Framework then no book covers it 100%.
It also depends on what you mean by "master" it. I've been writing C# for 5+ years now and I've not got 100% knowledge. However, I've got the next best thing: I know how to looks stuff up on MSDN and how to use an internet search engine.
|
|
|
|
|
You are right even I could not master any software 100%.
what I meant by that, was I am stuck with my thesis work simulation. I have provided with object codes and .dll files from company to which I am working. And they are providing me constant support.
I feel I should not ask small doubts to them and I want to learn by myself. I have MSDN and do you think that will be enough? in that case I will keep looking into that material.
Thank you;)
Haseeb
|
|
|
|
|
helpfulguy wrote: I feel I should not ask small doubts to them and I want to learn by myself.
Okay, just be careful here and learn when your questions relate to the .NET framework (in which case you can ask here) or other bits of software they are providing (in which case you should read their documentation* and ask them questions).
It is okay to want to learn by yourself, but if you are part of a team then you have a most valuable information resource right beside you. Don't be afraid to ask questions.
* If they provide you with any documentation at all
|
|
|
|
|
Hi
I am having trouble with a project I am working on. I started developing it in Studio.Net 2003 but I am now having to migrate it to 2005. I have a webpage that inherits from another class that inherits from System.Web.UI.Page.
In 2003 everything was fine - I started a new project in 2005 and added in the pages and classes i needed. I then try to build it and my webpage shows the error are you missing a using or assembly reference. The namespaces are from the classes my page inherits from and they are part of the project.
I have built the project without the page (just the classes) and it built fine but the page just cannot see the namespace.
I have also tried to add a reference but there is no reference to add in the project directory.
Any ideas where i am going wrong - I am sure it is something simple but any help would be much appreciated.
Thanks
Dan
|
|
|
|
|
You have a using statement for the namespace ? Or you scope it directly ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I have using Flyers.ParentPages at the top of my page
Then in a folder in the project named ParentPages and in it i have my parent pages which are like this
namespace Flyers.ParentPages
{
class here
}
Thanks
Dan
|
|
|
|
|
Some body please help me.I want to create DLL file in .NET 2005(Application).How can i do it ?.
Please intro me
Virus@comscI
|
|
|
|
|
just create a new project that creates a dll
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|