OneDrive/ODConnection.public.cs
/// <summary>
/// Upload a file from a URL.
/// </summary>
/// <param name="parentItemReference"></param>
/// <param name="sourceUrl"></param>
/// <param name="destinationFilename"></param>
/// <returns></returns>
Upload a file from a URL.
Upload a file from a URL .
public async Task<ODAsyncTask> UploadFromUrlAsync(ODItemReference parentItemReference, string sourceUrl, string destinationFilename)
        {
            if (!destinationFilename.ValidFilename())
                throw new ArgumentException("destinationFilename contains invalid characters.");
            if (!parentItemReference.IsValid())
                throw new ArgumentException("parentItemReference was invalid. Requires either an ID or Path");
            if (string.IsNullOrEmpty(sourceUrl))
                throw new ArgumentNullException("sourceUrl");
            Uri serviceUri = UriForItemReference(parentItemReference, ApiConstants.ChildrenRelationshipName);
            var request = await CreateHttpRequestAsync(serviceUri, ApiConstants.HttpPost);
            AddAsyncHeaders(request);
            var uploadItem = new ODItem { Name = destinationFilename, File = new Facets.FileFacet(), SourceUrlAnnotation = sourceUrl };
            await SerializeObjectToRequestBody(uploadItem, request);
            return await AsyncTaskResultForRequest(request, serviceUri);
        }
public async Task < ODAsyncTask > UploadFromUrlAsync ( ODItemReference parentItemReference , string sourceUrl , string destinationFilename ) { if ( ! destinationFilename . ValidFilename ( ) ) throw new ArgumentException ( " " ) ; if ( ! parentItemReference . IsValid ( ) ) throw new ArgumentException ( " " ) ; if ( string . IsNullOrEmpty ( sourceUrl ) ) throw new ArgumentNullException ( " " ) ; Uri serviceUri = UriForItemReference ( parentItemReference , ApiConstants . ChildrenRelationshipName ) ; var request = await CreateHttpRequestAsync ( serviceUri , ApiConstants . HttpPost ) ; AddAsyncHeaders ( request ) ; var uploadItem = new ODItem { Name = destinationFilename , File = new Facets . FileFacet ( ) , SourceUrlAnnotation = sourceUrl } ; await SerializeObjectToRequestBody ( uploadItem , request ) ; return await AsyncTaskResultForRequest ( request , serviceUri ) ; }
Upload a file from a URL.
Upload a file from a URL .
None
parentItemReference
ODItemReference
None
sourceUrl
string
None
destinationFilename
string
None