private IWebDAVStoreDocument CopyDocument(IWebDAVStoreDocument source, string destinationName) { IWebDAVStoreItem existingItem = GetItemByName(destinationName); if (existingItem != null) { Delete(existingItem); } IWebDAVStoreDocument destination = CreateDocument(destinationName); using (Stream sourceStream = source.OpenReadStream()) using (Stream destinationStream = destination.OpenWriteStream(false)) { sourceStream.CopyTo(destinationStream); } return(destination); }
private void MoveDocument(WebDAVServer server, IHttpListenerContext context, IWebDAVStore store, IWebDAVStoreDocument source) { var destinationUri = new Uri(context.Request.Headers["Destination"]); var destinationCollection = destinationUri.GetParentUri().GetItem(server, store) as IWebDAVStoreCollection; if (destinationCollection == null) { throw new HttpConflictException(); } bool isNew = true; string destinationName = destinationUri.Segments.Last().TrimEnd('/', '\\'); var destination = destinationCollection.GetItemByName(destinationName); if (destination != null) { if (context.Request.Headers["Overwrite"] == "F") { throw new HttpException(HttpStatusCodes.ClientErrors.PreconditionFailed); } if (destination is IWebDAVStoreCollection) { destinationCollection.Delete(destination); } isNew = false; } destinationCollection.MoveItemHere(source, destinationName); if (isNew) { context.SendSimpleResponse(HttpStatusCodes.Successful.Created); } else { context.SendSimpleResponse(HttpStatusCodes.Successful.NoContent); } }