private void BtnUpload_Click(object sender, EventArgs e) { var BrowseWin = new System.Windows.Forms.OpenFileDialog(); BrowseWin.Filter = "All Files (*.*)|*.*"; var ret = BrowseWin.ShowDialog(); if (ret == System.Windows.Forms.DialogResult.OK) { long FileVer = -1; string FileName = DirectoryTextBox.Text + BrowseWin.SafeFileName; foreach (FileMetaData file in FileList.fileMDList) { if (file.filepath == FileName) { FileVer = 1 + file.versionNumber; break; } } if (FileVer == -1) {// false FileVer = 1; } UpdateFile arg = new UpdateFile(); string LocalFilePath = BrowseWin.FileName; UserFile FileToUpload = new UserFile(FileName, ConnectedUser.ClientId); //byte[] fileStream = File.ReadAllBytes(LocalFilePath);` string fileStream = File.ReadAllText(LocalFilePath); //bool done = FileToUpload.SetFileContent(fileStream, (long)0); FileToUpload.SetFileContent(Encoding.UTF8.GetBytes(fileStream), FileVer); arg.file = FileToUpload; string requestUrl = string.Format("/updatefile/{0}/{1}", ConnectedUser.ClientId, ConnectedUser.Password); ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate); JsonServiceClient Updateclient = new JsonServiceClient(CLOUD_SERVICE_ENDPOINT); //Updateclient.ContentType = "application/json"; try { Updateclient.Post <Object>(requestUrl, arg); ClientFileSystem.addFileSynchronized(FileToUpload); // update clientfilesystem on upload } catch (Exception ex) { MessageBox.Show("This File has been changed by another client. Please download the latest copy and try to uplaod"); } //send file for Upload this.UpdateFileList(); } }
private void BtnUpload_Click(object sender, EventArgs e) { var BrowseWin = new System.Windows.Forms.OpenFileDialog(); BrowseWin.Filter = "All Files (*.*)|*.*"; var ret = BrowseWin.ShowDialog(); if (ret == System.Windows.Forms.DialogResult.OK) { long FileVer = -1; string FileName = DirectoryTextBox.Text + BrowseWin.SafeFileName; foreach (FileMetaData file in FileList.fileMDList) { if (file.filepath == FileName) { FileVer = 1 + file.versionNumber; break; } } if(FileVer == -1) {// false FileVer = 1; } UpdateFile arg = new UpdateFile(); string LocalFilePath = BrowseWin.FileName; UserFile FileToUpload = new UserFile(FileName, ConnectedUser.ClientId); //byte[] fileStream = File.ReadAllBytes(LocalFilePath);` string fileStream = File.ReadAllText(LocalFilePath); //bool done = FileToUpload.SetFileContent(fileStream, (long)0); FileToUpload.SetFileContent(Encoding.UTF8.GetBytes(fileStream), FileVer); arg.file = FileToUpload; string requestUrl = string.Format("/updatefile/{0}/{1}", ConnectedUser.ClientId, ConnectedUser.Password); ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate); JsonServiceClient Updateclient = new JsonServiceClient(CLOUD_SERVICE_ENDPOINT); //Updateclient.ContentType = "application/json"; try { Updateclient.Post<Object>(requestUrl, arg); ClientFileSystem.addFileSynchronized(FileToUpload); // update clientfilesystem on upload } catch(Exception ex) { MessageBox.Show("This File has been changed by another client. Please download the latest copy and try to uplaod"); } //send file for Upload this.UpdateFileList(); } }