|
-
January 24th, 2010, 02:16 PM
#6
Re: Open Help file......
 Originally Posted by rocky_upadhaya
Does this code given by arjay requires GetEntryAssembly method too? because it returned with "Error 1 The name 'Path' does not exist in the current context" Error
If you see this error, it means that it can't resolve which namespace the entity 'Path' is in. If you right click on the word 'Path', and choose 'Resolve...', you'll see two menu entries. Choose the 1st one, "using System.IO;' and this using directive will be inserted into your code.
Btw, msdn will specify what namespace these classes are in and what assembly. If you find a .net class where the "Resolve..." menu item doesn't appear, then most likely you don't have the correct assembly referenced. If it's a .net class, you can find which assembly needs to be added by looking up the class in msdn and then add a reference to the assembly by right clicking on the "References" item in the Solution Explorer and choose, "Add Reference...". From there, you can right click on the class, choose "Resolve", and add the using statement.
In msdn, the Path class is listed as:
.NET Framework Class Library
Path Class
Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
The namespace above tells you what using statement you need. The assembly tells you what assembly you need to reference. In this case, the mscorlib.dll is always referenced in a .net project, so you don't need to a an assembly reference (but you do need to add "using System.IO;" to your code).
Lastly, what exactly does Path.Combine do? It just simply takes two strings and joins them putting a '\' between them.
So if we have the following two path components:
Code:
string folder = @"C:\myFolder\myAppFolder";
string appName = "myApp.exe";
instead of joining them, like this
Code:
string fullPath = folder + @"\" + appName;
we can use the Path.Combine method
Code:
string fullPath = Path.Combine( folder, appName );
The benefit of using Path.Combine is that it will 'fix' up the strings as necessary with regard to any backslash characters.
So it will remove the extra backslash chars when combining the following:
Code:
string folder = @"C:\myFolder\myAppFolder\";
string appName = "\myApp.exe";
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|