private DragDropEffects DragDropFileByProjectItem(DocumentProjectItem sourceItem, string destinationPath) { if (File.Exists(destinationPath)) { IMxUIService service = (IMxUIService) base.GetService(typeof(IUIService)); if (service.ShowMessage("A file with the name '" + Path.GetFileName(destinationPath) + "' already exists in the target folder.\r\nDo you want to overwrite it?", string.Empty, MessageBoxIcon.Question, MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2) == DialogResult.No) { return DragDropEffects.None; } } DragDropEffects none = DragDropEffects.None; Stream stream = null; FileStream stream2 = null; try { stream = sourceItem.GetStream(ProjectItemStreamMode.Read); stream2 = new FileStream(destinationPath, FileMode.Create, FileAccess.Write, FileShare.None); byte[] buffer = new byte[0x1000]; while (true) { int count = stream.Read(buffer, 0, 0x1000); if (count <= 0) { break; } stream2.Write(buffer, 0, count); } none = DragDropEffects.Copy; } catch (Exception exception) { ((IMxUIService) base.GetService(typeof(IUIService))).ReportError(exception.Message, "Error copying the file to the target folder.", false); } finally { if (stream2 != null) { stream2.Close(); stream2 = null; } if (stream != null) { stream.Close(); stream = null; } } return none; }
private DragDropEffects DragDropFileByProjectItem(DocumentProjectItem sourceItem, string destinationPath) { DragDropEffects none = DragDropEffects.None; Stream sourceStream = null; try { sourceStream = sourceItem.GetStream(ProjectItemStreamMode.Read); if ((sourceItem is FileProjectItem) && (sourceItem.Project == this)) { MemoryStream stream2 = new MemoryStream(); byte[] buffer = new byte[0x1000]; while (true) { int count = sourceStream.Read(buffer, 0, 0x1000); if (count <= 0) { break; } stream2.Write(buffer, 0, count); } sourceStream.Close(); stream2.Seek(0L, SeekOrigin.Begin); sourceStream = stream2; } none = this.DragDropFileByStream(sourceStream, destinationPath); } finally { if (sourceStream != null) { sourceStream.Close(); sourceStream = null; } } return none; }