Click here to Skip to main content
15,888,461 members
Home / Discussions / C#
   

C#

 
QuestionActive X Control... Pin
priyareguri13-Aug-09 6:00
priyareguri13-Aug-09 6:00 
AnswerRe: Active X Control... Pin
Dave Kreskowiak13-Aug-09 7:12
mveDave Kreskowiak13-Aug-09 7:12 
GeneralRe: Active X Control... Pin
priyareguri18-Aug-09 3:21
priyareguri18-Aug-09 3:21 
QuestionGetRelativePath implementation ? Pin
Marc Clifton13-Aug-09 5:54
mvaMarc Clifton13-Aug-09 5:54 
AnswerRe: GetRelativePath implementation ? Pin
Luc Pattyn13-Aug-09 6:52
sitebuilderLuc Pattyn13-Aug-09 6:52 
GeneralRe: GetRelativePath implementation ? Pin
Marc Clifton13-Aug-09 9:18
mvaMarc Clifton13-Aug-09 9:18 
GeneralRe: GetRelativePath implementation ? Pin
Luc Pattyn13-Aug-09 9:48
sitebuilderLuc Pattyn13-Aug-09 9:48 
GeneralRe: GetRelativePath implementation ? [modified] Pin
Scott Dorman13-Aug-09 10:36
professionalScott Dorman13-Aug-09 10:36 
You can do this with some P/Invoke code:

public const int MAX_PATH = 260;
public const uint FILE_ATTRIBUTE_DIRECTORY = 0x10;
internal const string SHLWAPI = "shlwapi.dll";
 
[DllImport(SHLWAPI, CharSet = CharSet.Unicode)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool PathRelativePathTo([MarshalAsAttribute(UnmanagedType.LPWStr)] StringBuilder pszPath, [MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszFrom, uint dwAttrFrom, [MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszTo, uint dwAttrTo);
 
[DllImport(SHLWAPI, CharSet = CharSet.Unicode)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool PathIsDirectoryEmpty([MarshalAsAttribute(UnmanagedType.LPWStr), In] string pszPath);
 
/// <summary>
/// Creates a relative path from one file or folder to another.
/// </summary>
/// <param name="from">Contains the directory that defines the start of 
/// the relative path.</param>
/// <param name="to">Contains the path that defines the endpoint of the 
/// relative path.</param>
/// <returns>The relative path from the start directory to the end 
/// path.</returns>
public static string PathRelativePathTo(string from, string to)
{
    string result = String.Empty;
    StringBuilder path = new StringBuilder(MAX_PATH);
    uint fromAttributes = IsDirectory(from) ? FILE_ATTRIBUTE_DIRECTORY : 0;
    uint toAttributes = IsDirectory(to) ? FILE_ATTRIBUTE_DIRECTORY : 0;
 
    if (PathRelativePathTo(path, from, fromAttributes, to, toAttributes))
    {
	result = path.ToString();
    }
 
    return result;
}
 
/// <summary>
/// Verifies that a path is a valid directory.
/// </summary>
/// <param name="path">The path to verify.</param>
/// <returns><see langword="true"/> if the path is a valid directory; 
/// otherwise, <see langword="false"/>.</returns>
public static bool IsDirectory(string path)
{
    return PathIsDirectory(path);
}


Scott Dorman
Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA

[Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

modified on Thursday, August 13, 2009 7:49 PM

GeneralRe: GetRelativePath implementation ? Pin
Luc Pattyn13-Aug-09 13:26
sitebuilderLuc Pattyn13-Aug-09 13:26 
GeneralRe: GetRelativePath implementation ? Pin
Scott Dorman13-Aug-09 13:48
professionalScott Dorman13-Aug-09 13:48 
AnswerRe: GetRelativePath implementation ? Pin
Scott Dorman13-Aug-09 13:50
professionalScott Dorman13-Aug-09 13:50 
QuestionButton Click event help Pin
spankyleo12313-Aug-09 4:51
spankyleo12313-Aug-09 4:51 
AnswerRe: Button Click event help Pin
stancrm13-Aug-09 4:55
stancrm13-Aug-09 4:55 
GeneralRe: Button Click event help Pin
spankyleo12313-Aug-09 5:15
spankyleo12313-Aug-09 5:15 
QuestionCant find SQL ServerCE.dll Pin
sohaib_a13-Aug-09 4:47
sohaib_a13-Aug-09 4:47 
QuestionProblem in including namespace Pin
Sivaji156513-Aug-09 4:42
Sivaji156513-Aug-09 4:42 
AnswerRe: Problem in including namespace Pin
benjymous13-Aug-09 4:49
benjymous13-Aug-09 4:49 
GeneralRe: Problem in including namespace Pin
Sivaji156513-Aug-09 18:47
Sivaji156513-Aug-09 18:47 
AnswerRe: Problem in including namespace Pin
stancrm13-Aug-09 4:49
stancrm13-Aug-09 4:49 
GeneralRe: Problem in including namespace Pin
riced13-Aug-09 5:45
riced13-Aug-09 5:45 
QuestionSee the monitor from another Pc on network? Pin
nhqlbaislwfiikqraqnm13-Aug-09 4:27
nhqlbaislwfiikqraqnm13-Aug-09 4:27 
AnswerRe: See the monitor from another Pc on network? Pin
stancrm13-Aug-09 4:48
stancrm13-Aug-09 4:48 
GeneralRe: See the monitor from another Pc on network? Pin
nhqlbaislwfiikqraqnm13-Aug-09 6:36
nhqlbaislwfiikqraqnm13-Aug-09 6:36 
GeneralRe: See the monitor from another Pc on network? Pin
nhqlbaislwfiikqraqnm14-Aug-09 0:31
nhqlbaislwfiikqraqnm14-Aug-09 0:31 
QuestionError while adding TreeNode in presenter. Pin
Krishna Aditya13-Aug-09 4:10
Krishna Aditya13-Aug-09 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.