OneDrive/ODConnection.public.cs
/// <summary>
/// Upload a new file to a parent folder item.
/// </summary>
/// <param name="parentItemReference">Item ID for the parent folder.</param>
/// <param name="filename">Filename of the new file to create</param>
/// <param name="sourceFileStream">Data stream for the new file</param>
/// <param name="options">Upload options</param>
/// <returns></returns>
Upload a new file to a parent folder item.
Upload a new file to a parent folder item .
public async Task<ODItem> PutNewFileToParentItemAsync(ODItemReference parentItemReference, string filename, Stream sourceFileStream, ItemUploadOptions options)
        {
            if (!filename.ValidFilename())
                throw new ArgumentException("Filename contains invalid characters.");
            if (!parentItemReference.IsValid())
                throw new ArgumentException("parentItemReference was invalid. Requires either an ID or Path");
            if (null == options)
                throw new ArgumentNullException("options");
            if (null == sourceFileStream)
                throw new ArgumentNullException("sourceFileStream");
            if (sourceFileStream.Length > MaxRegularUploadSize)
                throw new ODException("Stream is longer than the maximum upload size allowed.");
            long localItemSize;
            if (!sourceFileStream.TryGetLength(out localItemSize))
            {
                System.Diagnostics.Debug.WriteLine("Warning: Couldn't determine length of sourceFileStream.");
            }
            string navigationValue = string.Concat(ApiConstants.ChildrenRelationshipName, UrlSeperator, filename, UrlSeperator, ApiConstants.ContentRelationshipName);
            Uri serviceUri = UriForItemReference(parentItemReference, navigationValue);
            await CreateHttpRequestAsync(serviceUri, ApiConstants.HttpPut);
            return await UploadToUrl(sourceFileStream, options, localItemSize, serviceUri);
        }
public async Task < ODItem > PutNewFileToParentItemAsync ( ODItemReference parentItemReference , string filename , Stream sourceFileStream , ItemUploadOptions options ) { if ( ! filename . ValidFilename ( ) ) throw new ArgumentException ( " " ) ; if ( ! parentItemReference . IsValid ( ) ) throw new ArgumentException ( " " ) ; if ( null == options ) throw new ArgumentNullException ( " " ) ; if ( null == sourceFileStream ) throw new ArgumentNullException ( " " ) ; if ( sourceFileStream . Length > MaxRegularUploadSize ) throw new ODException ( " " ) ; long localItemSize ; if ( ! sourceFileStream . TryGetLength ( out localItemSize ) ) { System . Diagnostics . Debug . WriteLine ( " " ) ; } string navigationValue = string . Concat ( ApiConstants . ChildrenRelationshipName , UrlSeperator , filename , UrlSeperator , ApiConstants . ContentRelationshipName ) ; Uri serviceUri = UriForItemReference ( parentItemReference , navigationValue ) ; await CreateHttpRequestAsync ( serviceUri , ApiConstants . HttpPut ) ; return await UploadToUrl ( sourceFileStream , options , localItemSize , serviceUri ) ; }
Upload a new file to a parent folder item.
Upload a new file to a parent folder item .
None
parentItemReference
ODItemReference
Item ID for the parent folder.
Item ID for the parent folder .
filename
string
Filename of the new file to create
Filename of the new file to create
sourceFileStream
Stream
Data stream for the new file
Data stream for the new file
options
ItemUploadOptions
None