OneDrive/ODConnection.cs
/// <summary>
/// Return the URL for the service based on an item reference, navigation path (optional) and query string (optional)
/// </summary>
/// <param name="itemReference"></param>
/// <param name="navigationPath"></param>
/// <param name="queryString"></param>
/// <returns></returns>
Return the URL for the service based on an item reference, navigation path (optional) and query string (optional)
Return the URL for the service based on an item reference navigation path ( optional ) and query string ( optional )
private Uri UriForItemReference(ODItemReference itemReference, string navigationPath = null, QueryStringBuilder queryString = null)
        {
            StringBuilder url = new StringBuilder(RootUrl);
            if (!string.IsNullOrEmpty(itemReference.Id))
            {
                if  (!string.IsNullOrEmpty(itemReference.DriveId)) 
                {
                    url.AppendFormat("/drives/{0}", itemReference.DriveId);
                }
                else
                { 
                    url.AppendFormat("/drive");
                }
                url.AppendFormat("/items/{0}", itemReference.Id);
            }
            else if (!string.IsNullOrEmpty(itemReference.Path))
            {
                if (!itemReference.Path.StartsWith("/drive", StringComparison.Ordinal))
                    throw new ArgumentException("Invalid ODItemReference: Path doesn't start with \"/drive\" or \"/drives\".");
                url.Append(itemReference.Path);
                if (itemReference.Path.OccurrencesOfCharacter(':') == 1)
                {
                    url.Append(":");
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(itemReference.DriveId))
                {
                    url.AppendFormat("/drives/{0}", itemReference.DriveId);
                }
                else
                {
                    url.AppendFormat("/drive");
                }
            }
            if (!string.IsNullOrEmpty(navigationPath))
            {
                if (url[url.Length - 1] != '/')
                    url.AppendFormat("/");
                url.Append(navigationPath);
            }
            UriBuilder builder = new UriBuilder(url.ToString());
            if (null != queryString && queryString.HasKeys)
            {
                builder.Query = queryString.ToString();
            }
#if DEBUG
            System.Diagnostics.Debug.WriteLine("URL: " + builder.Uri);
#endif
            return builder.Uri;
        }
private Uri UriForItemReference ( ODItemReference itemReference , string navigationPath = null , QueryStringBuilder queryString = null ) { StringBuilder url = new StringBuilder ( RootUrl ) ; if ( ! string . IsNullOrEmpty ( itemReference . Id ) ) { if ( ! string . IsNullOrEmpty ( itemReference . DriveId ) ) { url . AppendFormat ( " " , itemReference . DriveId ) ; } else { url . AppendFormat ( " " ) ; } url . AppendFormat ( " " , itemReference . Id ) ; } else if ( ! string . IsNullOrEmpty ( itemReference . Path ) ) { if ( ! itemReference . Path . StartsWith ( " " , StringComparison . Ordinal ) ) throw new ArgumentException ( " \" \" \" \" " ) ; url . Append ( itemReference . Path ) ; if ( itemReference . Path . OccurrencesOfCharacter ( ' ' ) == 1 ) { url . Append ( " " ) ; } } else { if ( ! string . IsNullOrEmpty ( itemReference . DriveId ) ) { url . AppendFormat ( " " , itemReference . DriveId ) ; } else { url . AppendFormat ( " " ) ; } } if ( ! string . IsNullOrEmpty ( navigationPath ) ) { if ( url [ url . Length - 1 ] != ' ' ) url . AppendFormat ( " " ) ; url . Append ( navigationPath ) ; } UriBuilder builder = new UriBuilder ( url . ToString ( ) ) ; if ( null != queryString && queryString . HasKeys ) { builder . Query = queryString . ToString ( ) ; } if DEBUG System . Diagnostics . Debug . WriteLine ( " " + builder . Uri ) ; endif return builder . Uri ; }
Return the URL for the service based on an item reference, navigation path (optional) and query string (optional)
Return the URL for the service based on an item reference navigation path ( optional ) and query string ( optional )
// RootUrl = "https://api.onedrive.com/v1.0" // Make sure we terminate the path escape so we can add a navigation property if necessary // Just address the drive if both path & id are null.
None
itemReference
ODItemReference
None
navigationPath
string
None
queryString
QueryStringBuilder
None