public string DownloadLargeFile( string remoteFileName, string remoteDirectory, string destFilePath, out string[] arrFilePart) { List<String> listFilePart = new List<string>(); string descriptionFileName = remoteFileName + LocalFileSystem.LargeLocalFileInfo.FILE_NAME_EXT; // create an instance fo the web service uploaderWS.FileUploader srv = newUploader(); uploaderWS.FileContent[] descriptionFileContent = srv.DownloadFile(sessionID_, descriptionFileName, remoteDirectory); listFilePart.Add(remoteDirectory + "\\" + descriptionFileName); string fileNameOnServer = descriptionFileContent[0].path_; fileNameOnServer = fileNameOnServer.Substring(0, fileNameOnServer.Length - LocalFileSystem.LargeLocalFileInfo.FILE_NAME_EXT.Length); WSFileSystemEventArgs e = new WSFileSystemEventArgs(); e.filePath_ = fileNameOnServer; string[] fileParts = content2string(descriptionFileContent[0].content_); listFilePart.AddRange(fileParts); e.partCount_ = fileParts.Length; foreach (string filePart in fileParts) { uploaderWS.FileContent[] partData = srv.DownloadFile( sessionID_, getFileName(filePart), getFolder(filePart)); LocalFileSystem.LocalFileSystemUtil.writeFile(partData[0].content_, destFilePath, FileMode.Append); e.part_++; RaiseWSFileSystemEvent(e); } // // arrFilePart = listFilePart.ToArray(); return fileNameOnServer; }
void RaiseWSFileSystemEvent(WSFileSystemEventArgs e) { if( WSFileSystemEvent != null ) WSFileSystemEvent(this, e); }
void onWSFileSystemEvent(object Sender, WSFileSystemEventArgs e) { lblFileName.Text = e.filePath_; lblProgross.Text = string.Format("{0} of {1}", e.part_, e.partCount_); }
/// <summary> /// Upload any file to the web service; this function may be /// used in any application where it is necessary to upload /// a file through a web service /// </summary> /// <param name="localFilePath">Pass the file path to upload</param> public string UploadLargeFile(string localFilePath, string remoteFolder) { // get the exact file name from the path String strFile = System.IO.Path.GetFileName(localFilePath); // create an instance fo the web service uploaderWS.FileUploader srv = newUploader(); LocalFileSystem.LargeLocalFileReader file = new LocalFileSystem.LargeLocalFileReader(localFilePath, 4*1024);//4K WSFileSystemEventArgs e = new WSFileSystemEventArgs(); e.filePath_ = localFilePath; e.partCount_ = file.getFilePartCount(); string msg = ""; List<String> fileParts = new List<string>(); for (int i = 0; i < file.getFilePartCount(); i++) { byte[] data = file.readFilePart(i); string fileName = getFileName(localFilePath)+"-part" + i.ToString().PadLeft(8, '0'); string sTmp = srv.UploadFile(sessionID_, data, remoteFolder + "\\" + fileName); e.part_++; RaiseWSFileSystemEvent(e); fileParts.Add(sTmp); msg += "\n" + sTmp; // this will always say OK unless an error occurs, // if an error occurs, the service returns the error message #if false if ( MessageBox.Show("File Upload Status: Part %" + i.ToString() + " of "+ file.getFilePartCount().ToString()+ ":" + sTmp, "File Upload", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ) == System.Windows.Forms.DialogResult.Cancel) break; #endif } //write large info file { byte[] data = LocalFileSystem.LargeLocalFileInfo.buildContent(fileParts.ToArray()); string largeFileName = remoteFolder + "\\" + getFileName(localFilePath) + LocalFileSystem.LargeLocalFileInfo.FILE_NAME_EXT; string sTmp = srv.UploadFile(sessionID_, data, largeFileName); msg += "\n" + sTmp; } return msg; }
void onWSFileSystemEvent(object Sender, WSFileSystemEventArgs e) { System.Console.Write(string.Format("{0}/{1}. ", e.part_, e.partCount_)); }