Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void adxExcelEvents_WorkbookBeforeSave(object sender, ADXHostBeforeSaveEventArgs e)
- {
- if (this.ExcelApp != null)
- {
- try
- {
- if (ExcelApp.ActiveWorkbook.Path != "")
- {
- string url = ExcelApp.ActiveWorkbook.Path;
- string del = string.Empty;
- if (url.Contains("\\"))
- {
- del = "\\";
- }
- string[] splitUrl = url.Split(del.ToCharArray());
- Stringindex = 0;
- for (int i = 0; i < splitUrl.Length; i++)
- {
- if (splitUrl[i] == "DownloadedFiles")
- {
- Stringindex = i;
- break;
- }
- }
- if (splitUrl[Stringindex] == "DownloadedFiles" && splitUrl[Stringindex - 1] == "SharePoint" && splitUrl[Stringindex - 2] == "AddInExpress"
- && splitUrl[Stringindex - 3] == "Litera")
- {
- if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
- {
- String[] check = splitUrl[Stringindex + 1].Split('_');
- String strLocalFilePath = ExcelApp.ActiveWorkbook.Path + @"\" + ExcelApp.ActiveWorkbook.Name;
- templocaldescription = check[1];
- check = null;
- check = splitUrl[Stringindex + 2].Split('_');
- templocalfolderID = check[1];
- check = null;
- check = splitUrl[Stringindex + 3].Split('_');
- templocalfileID = check[1];
- check = null;
- check = splitUrl[Stringindex + 4].Split('_');
- templocalVersion = check[1];
- check = null;
- templocalfilename = ExcelApp.ActiveWorkbook.Name;
- readXmldoc();
- for (int i = 0; i < a; i++)
- {
- if (description[i] == templocaldescription)
- {
- templocalUrl = sitepath[i];
- templocalUserName = UserName[i];
- templocalPassword = Password[i];
- templocalDomain = Domain[i];
- }
- }
- //var application = (Excel.Application)ExcelApp;
- //application.ActiveWorkbook.Save();
- //ExcelApp.SaveWorkspace(Filename: url);
- ExcelApp.ActiveWorkbook.Save();
- UploadNewFiletoList(templocalUrl, templocalUserName, templocalPassword, templocalDomain, templocalfolderID, templocalfilename, strLocalFilePath);
- }
- else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == true)
- {
- //Call a browse files dialog box & intialize variables
- string strFileLocation = "";
- string strDirectory = @"C:\Users\Administrator\Desktop";
- //Save File
- SaveFileDialog saveFile = new SaveFileDialog();
- // Default file extension
- saveFile.DefaultExt = "docx";
- saveFile.FileName = ExcelApp.ActiveWorkbook.Name;
- // Available file extensions
- saveFile.Filter = "Doc Files (*.doc, *.docx)|Excel Files (*.xls, *.xlsx)|Adobe Files (*.pdf)|Image Files (*.jpg," + "*.jpeg,*.bmp, *.tiff, *.giff, *.png)" + "|All files (*.*)|*.*";
- saveFile.Filter = "All files (*.*)|*.*";
- saveFile.FilterIndex = 1;
- // Adds a extension if the user does not
- saveFile.AddExtension = true;
- // Restores the selected directory, next time
- saveFile.RestoreDirectory = true;
- // Dialog title
- saveFile.Title = "Where do you want to save the file?";
- saveFile.OverwritePrompt = true;
- // Startup directory
- saveFile.InitialDirectory = strDirectory;
- // Show the dialog and process the result selectedFileRowIndex,sLFVerName_global,sLFVerID_global
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- strFileLocation = saveFile.FileName;
- //fileName = saveFile.SafeFileName;
- object missing = Type.Missing;
- ExcelApp.ActiveWorkbook.SaveAs(Filename: strFileLocation);
- frmSelectFolder frmSelectFolder = new frmSelectFolder();
- frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
- frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
- frmSelectFolder.ShowDialog();
- e.Cancel = true;
- }
- else
- e.Cancel = true;
- }
- else
- return;
- }
- else
- {
- try
- {
- if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
- {
- ExcelApp.ActiveWorkbook.Save();
- frmSelectFolder frmSelectFolder = new frmSelectFolder();
- frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
- frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
- frmSelectFolder.ShowDialog();
- }
- else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == true)
- {
- //Call a browse files dialog box & intialize variables
- string strFileLocation = "";
- string strDirectory = @"C:\Users\Administrator\Desktop";
- //Save File
- SaveFileDialog saveFile = new SaveFileDialog();
- // Default file extension
- saveFile.DefaultExt = "docx";
- saveFile.FileName = ExcelApp.ActiveWorkbook.Name;
- // Available file extensions
- saveFile.Filter = "Doc Files (*.doc, *.docx)|Excel Files (*.xls, *.xlsx)|Adobe Files (*.pdf)|Image Files (*.jpg," + "*.jpeg,*.bmp, *.tiff, *.giff, *.png)" + "|All files (*.*)|*.*";
- saveFile.Filter = "All files (*.*)|*.*";
- saveFile.FilterIndex = 1;
- // Adds a extension if the user does not
- saveFile.AddExtension = true;
- // Restores the selected directory, next time
- saveFile.RestoreDirectory = true;
- // Dialog title
- saveFile.Title = "Where do you want to save the file?";
- saveFile.OverwritePrompt = true;
- // Startup directory
- saveFile.InitialDirectory = strDirectory;
- // Show the dialog and process the result selectedFileRowIndex,sLFVerName_global,sLFVerID_global
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- strFileLocation = saveFile.FileName;
- //fileName = saveFile.SafeFileName;
- object missing = Type.Missing;
- ExcelApp.ActiveWorkbook.SaveAs(Filename: strFileLocation);
- frmSelectFolder frmSelectFolder = new frmSelectFolder();
- frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
- frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
- frmSelectFolder.ShowDialog();
- e.Cancel = true;
- }
- else
- e.Cancel = true;
- }
- else
- return;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- else
- {
- try
- {
- if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
- {
- ExcelApp.ActiveWorkbook.Save();
- }
- else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == true)
- {
- //Call a browse files dialog box & intialize variables
- string strFileLocation = "";
- string strDirectory = @"C:\Users\Administrator\Desktop";
- //Save File
- SaveFileDialog saveFile = new SaveFileDialog();
- // Default file extension
- saveFile.DefaultExt = "xlsx";
- saveFile.FileName = ExcelApp.ActiveWorkbook.Name;
- // Available file extensions
- saveFile.Filter = "Excel Files (*.xls, *.xlsx)|Doc Files (*.doc, *.docx)|Adobe Files (*.pdf)|Image Files (*.jpg," + "*.jpeg,*.bmp, *.tiff, *.giff, *.png)" + "|All files (*.*)|*.*";
- saveFile.Filter = "All files (*.*)|*.*";
- saveFile.FilterIndex = 1;
- // Adds a extension if the user does not
- saveFile.AddExtension = true;
- // Restores the selected directory, next time
- saveFile.RestoreDirectory = true;
- // Dialog title
- saveFile.Title = "Where do you want to save the file?";
- saveFile.OverwritePrompt = true;
- // Startup directory
- saveFile.InitialDirectory = strDirectory;
- // Show the dialog and process the result selectedFileRowIndex,sLFVerName_global,sLFVerID_global
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- strFileLocation = saveFile.FileName;
- //fileName = saveFile.SafeFileName;
- object missing = Type.Missing;
- ExcelApp.ActiveWorkbook.SaveAs(Filename: strFileLocation);
- frmSelectFolder frmSelectFolder = new frmSelectFolder();
- frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
- frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
- frmSelectFolder.ShowDialog();
- e.Cancel = true;
- }
- else
- e.Cancel = true;
- }
- else
- return;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
Add Comment
Please, Sign In to add comment