Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

The Ultimate Toolbox URL Class

0.00/5 (No votes)
25 Aug 2007 1  
A simple URL/UNC composition class from the The Ultimate Toolbox

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Source code and project files for this sample are included in the samples\file\URLDemo directory of the sample projects download.

Overview

The COXURL class represents a URL (like the one you use in your Internet browser).

It can divide a URL into different parts or compose a new URL from its parts.

The three parts of a URL are:

  • Protocol
  • Port
  • UNC

The protocol and port are important when using TCP/IP. Another important part is the UNC which can also be used separately.

URL and UNC classes represent a file (or other resource). A full URL (Uniform Resource locator) and a UNC (Universal Naming Convention) supports a new base class for file management functions useful to build applications that conform to the Win95 specifications (which requires UNC support). They are also useful to add internet functionality to your application.

The COXUNC and COXURL classes are simple to use - the samples\file\URLDemo sample simply includes OXURL.h and OXIteratorUNC.h headers and declares temporary objects to parse the string to show the 'splitting' functionality for UNC and URL strings:

void CURLDemoDlg::OnSplitUNC() 
    {
    if (!UpdateData(TRUE))
        return;

    COXUNC UNC;
    UNC = m_sURL_UNC;
    UNC.URLPart() = m_bURLPart;

    m_sServer = UNC.Server();
    m_sShare = UNC.Share();
    m_sDirectory = UNC.Directory();
    m_sFile = UNC.File();
    m_sBaseName = UNC.Base();
    m_sExtension = UNC.Extension();
    m_bURLPart = UNC.URLPart();
    ...

The full functionality of the UNC class includes a lot of actions on the actual files or directories like create, delete, rename, move, get directories, and change size, attributes and file times.

void CURLDemoDlg::OnSplitURL() 
    {
    if (!UpdateData(TRUE))
        return;

    COXURL URL;
    URL = m_sURL_UNC;

    // Get the result


    m_sProtocol = URL.Protocol();
    m_nPort = URL.Port();
    m_sServer = URL.UNC().Server();
    m_sShare = URL.UNC().Share();
    m_sDirectory = URL.UNC().Directory();
    m_sFile = URL.UNC().File();
    m_sBaseName = URL.UNC().Base();
    m_sExtension = URL.UNC().Extension();
    m_bURLPart = URL.UNC().URLPart();

    // Get the input parameters again 


    m_sURL_UNC = URL;

    m_sShare.Empty();

    UpdateData(FALSE);
}

A complete class reference for the COXURL and COXUNC and related classes is available in the compiled HTML documentation.

History

Initial CodeProject release August 2007.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here