Guest User

Untitled

a guest
Dec 25th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.99 KB | None | 0 0
  1. private void adxExcelEvents_WorkbookBeforeSave(object sender, ADXHostBeforeSaveEventArgs e)
  2. {
  3. if (this.ExcelApp != null)
  4. {
  5. try
  6. {
  7. if (ExcelApp.ActiveWorkbook.Path != "")
  8. {
  9.  
  10. string url = ExcelApp.ActiveWorkbook.Path;
  11. string del = string.Empty;
  12.  
  13. if (url.Contains("\\"))
  14. {
  15. del = "\\";
  16. }
  17. string[] splitUrl = url.Split(del.ToCharArray());
  18. Stringindex = 0;
  19. for (int i = 0; i < splitUrl.Length; i++)
  20. {
  21. if (splitUrl[i] == "DownloadedFiles")
  22. {
  23. Stringindex = i;
  24. break;
  25. }
  26. }
  27. if (splitUrl[Stringindex] == "DownloadedFiles" && splitUrl[Stringindex - 1] == "SharePoint" && splitUrl[Stringindex - 2] == "AddInExpress"
  28. && splitUrl[Stringindex - 3] == "Litera")
  29. {
  30. if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
  31. {
  32. String[] check = splitUrl[Stringindex + 1].Split('_');
  33. String strLocalFilePath = ExcelApp.ActiveWorkbook.Path + @"\" + ExcelApp.ActiveWorkbook.Name;
  34. templocaldescription = check[1];
  35. check = null;
  36. check = splitUrl[Stringindex + 2].Split('_');
  37. templocalfolderID = check[1];
  38. check = null;
  39. check = splitUrl[Stringindex + 3].Split('_');
  40. templocalfileID = check[1];
  41. check = null;
  42. check = splitUrl[Stringindex + 4].Split('_');
  43. templocalVersion = check[1];
  44. check = null;
  45. templocalfilename = ExcelApp.ActiveWorkbook.Name;
  46. readXmldoc();
  47. for (int i = 0; i < a; i++)
  48. {
  49. if (description[i] == templocaldescription)
  50. {
  51. templocalUrl = sitepath[i];
  52. templocalUserName = UserName[i];
  53. templocalPassword = Password[i];
  54. templocalDomain = Domain[i];
  55. }
  56. }
  57. //var application = (Excel.Application)ExcelApp;
  58. //application.ActiveWorkbook.Save();
  59. //ExcelApp.SaveWorkspace(Filename: url);
  60. ExcelApp.ActiveWorkbook.Save();
  61. UploadNewFiletoList(templocalUrl, templocalUserName, templocalPassword, templocalDomain, templocalfolderID, templocalfilename, strLocalFilePath);
  62. }
  63. else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == true)
  64. {
  65. //Call a browse files dialog box & intialize variables
  66. string strFileLocation = "";
  67. string strDirectory = @"C:\Users\Administrator\Desktop";
  68. //Save File
  69. SaveFileDialog saveFile = new SaveFileDialog();
  70. // Default file extension
  71. saveFile.DefaultExt = "docx";
  72. saveFile.FileName = ExcelApp.ActiveWorkbook.Name;
  73. // Available file extensions
  74. saveFile.Filter = "Doc Files (*.doc, *.docx)|Excel Files (*.xls, *.xlsx)|Adobe Files (*.pdf)|Image Files (*.jpg," + "*.jpeg,*.bmp, *.tiff, *.giff, *.png)" + "|All files (*.*)|*.*";
  75. saveFile.Filter = "All files (*.*)|*.*";
  76. saveFile.FilterIndex = 1;
  77. // Adds a extension if the user does not
  78. saveFile.AddExtension = true;
  79. // Restores the selected directory, next time
  80. saveFile.RestoreDirectory = true;
  81. // Dialog title
  82. saveFile.Title = "Where do you want to save the file?";
  83. saveFile.OverwritePrompt = true;
  84. // Startup directory
  85. saveFile.InitialDirectory = strDirectory;
  86. // Show the dialog and process the result selectedFileRowIndex,sLFVerName_global,sLFVerID_global
  87. if (saveFile.ShowDialog() == DialogResult.OK)
  88. {
  89. strFileLocation = saveFile.FileName;
  90. //fileName = saveFile.SafeFileName;
  91. object missing = Type.Missing;
  92. ExcelApp.ActiveWorkbook.SaveAs(Filename: strFileLocation);
  93. frmSelectFolder frmSelectFolder = new frmSelectFolder();
  94. frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
  95. frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
  96. frmSelectFolder.ShowDialog();
  97. e.Cancel = true;
  98. }
  99. else
  100. e.Cancel = true;
  101. }
  102. else
  103. return;
  104. }
  105. else
  106. {
  107. try
  108. {
  109. if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
  110. {
  111. ExcelApp.ActiveWorkbook.Save();
  112. frmSelectFolder frmSelectFolder = new frmSelectFolder();
  113. frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
  114. frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
  115. frmSelectFolder.ShowDialog();
  116. }
  117. else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == true)
  118. {
  119. //Call a browse files dialog box & intialize variables
  120. string strFileLocation = "";
  121. string strDirectory = @"C:\Users\Administrator\Desktop";
  122. //Save File
  123. SaveFileDialog saveFile = new SaveFileDialog();
  124. // Default file extension
  125. saveFile.DefaultExt = "docx";
  126. saveFile.FileName = ExcelApp.ActiveWorkbook.Name;
  127. // Available file extensions
  128. saveFile.Filter = "Doc Files (*.doc, *.docx)|Excel Files (*.xls, *.xlsx)|Adobe Files (*.pdf)|Image Files (*.jpg," + "*.jpeg,*.bmp, *.tiff, *.giff, *.png)" + "|All files (*.*)|*.*";
  129. saveFile.Filter = "All files (*.*)|*.*";
  130. saveFile.FilterIndex = 1;
  131. // Adds a extension if the user does not
  132. saveFile.AddExtension = true;
  133. // Restores the selected directory, next time
  134. saveFile.RestoreDirectory = true;
  135. // Dialog title
  136. saveFile.Title = "Where do you want to save the file?";
  137. saveFile.OverwritePrompt = true;
  138. // Startup directory
  139. saveFile.InitialDirectory = strDirectory;
  140. // Show the dialog and process the result selectedFileRowIndex,sLFVerName_global,sLFVerID_global
  141. if (saveFile.ShowDialog() == DialogResult.OK)
  142. {
  143. strFileLocation = saveFile.FileName;
  144. //fileName = saveFile.SafeFileName;
  145. object missing = Type.Missing;
  146. ExcelApp.ActiveWorkbook.SaveAs(Filename: strFileLocation);
  147. frmSelectFolder frmSelectFolder = new frmSelectFolder();
  148. frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
  149. frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
  150. frmSelectFolder.ShowDialog();
  151. e.Cancel = true;
  152. }
  153. else
  154. e.Cancel = true;
  155. }
  156. else
  157. return;
  158. }
  159. catch (Exception ex)
  160. {
  161. MessageBox.Show(ex.Message);
  162. }
  163. }
  164. }
  165. else
  166. {
  167. try
  168. {
  169. if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
  170. {
  171. ExcelApp.ActiveWorkbook.Save();
  172. }
  173. else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == true)
  174. {
  175. //Call a browse files dialog box & intialize variables
  176. string strFileLocation = "";
  177. string strDirectory = @"C:\Users\Administrator\Desktop";
  178. //Save File
  179. SaveFileDialog saveFile = new SaveFileDialog();
  180. // Default file extension
  181. saveFile.DefaultExt = "xlsx";
  182. saveFile.FileName = ExcelApp.ActiveWorkbook.Name;
  183. // Available file extensions
  184. saveFile.Filter = "Excel Files (*.xls, *.xlsx)|Doc Files (*.doc, *.docx)|Adobe Files (*.pdf)|Image Files (*.jpg," + "*.jpeg,*.bmp, *.tiff, *.giff, *.png)" + "|All files (*.*)|*.*";
  185. saveFile.Filter = "All files (*.*)|*.*";
  186. saveFile.FilterIndex = 1;
  187. // Adds a extension if the user does not
  188. saveFile.AddExtension = true;
  189. // Restores the selected directory, next time
  190. saveFile.RestoreDirectory = true;
  191. // Dialog title
  192. saveFile.Title = "Where do you want to save the file?";
  193. saveFile.OverwritePrompt = true;
  194. // Startup directory
  195. saveFile.InitialDirectory = strDirectory;
  196. // Show the dialog and process the result selectedFileRowIndex,sLFVerName_global,sLFVerID_global
  197. if (saveFile.ShowDialog() == DialogResult.OK)
  198. {
  199. strFileLocation = saveFile.FileName;
  200. //fileName = saveFile.SafeFileName;
  201. object missing = Type.Missing;
  202. ExcelApp.ActiveWorkbook.SaveAs(Filename: strFileLocation);
  203. frmSelectFolder frmSelectFolder = new frmSelectFolder();
  204. frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
  205. frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
  206. frmSelectFolder.ShowDialog();
  207. e.Cancel = true;
  208. }
  209. else
  210. e.Cancel = true;
  211. }
  212. else
  213. return;
  214. }
  215. catch (Exception ex)
  216. {
  217. MessageBox.Show(ex.Message);
  218. }
  219. }
  220. }
  221. catch (Exception ex)
  222. {
  223. MessageBox.Show(ex.Message);
  224. }
  225. }
  226. }
Add Comment
Please, Sign In to add comment