Guest User

Untitled

a guest
Dec 25th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.83 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. ExcelApp.ActiveWorkbook.Save();
  33. String[] check = splitUrl[Stringindex + 1].Split('_');
  34. String strLocalFilePath = ExcelApp.ActiveWorkbook.Path + @"\" + ExcelApp.ActiveWorkbook.Name;
  35. templocaldescription = check[1];
  36. check = null;
  37. check = splitUrl[Stringindex + 2].Split('_');
  38. templocalfolderID = check[1];
  39. check = null;
  40. check = splitUrl[Stringindex + 3].Split('_');
  41. templocalfileID = check[1];
  42. check = null;
  43. check = splitUrl[Stringindex + 4].Split('_');
  44. templocalVersion = check[1];
  45. check = null;
  46. templocalfilename = ExcelApp.ActiveWorkbook.Name;
  47. readXmldoc();
  48. for (int i = 0; i < a; i++)
  49. {
  50. if (description[i] == templocaldescription)
  51. {
  52. templocalUrl = sitepath[i];
  53. templocalUserName = UserName[i];
  54. templocalPassword = Password[i];
  55. templocalDomain = Domain[i];
  56. }
  57. }
  58. //var application = (Excel.Application)ExcelApp;
  59. //application.ActiveWorkbook.Save();
  60. //ExcelApp.SaveWorkspace(Filename: url);
  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)
  110. {
  111. ExcelApp.ActiveWorkbook.Save();
  112. }
  113. if (ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
  114. {
  115. //ExcelApp.ActiveWorkbook.Save();
  116. frmSelectFolder frmSelectFolder = new frmSelectFolder();
  117. frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
  118. frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
  119. frmSelectFolder.ShowDialog();
  120. }
  121. else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
  122. {
  123. //ExcelApp.ActiveWorkbook.Save();
  124. frmSelectFolder frmSelectFolder = new frmSelectFolder();
  125. frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
  126. frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
  127. frmSelectFolder.ShowDialog();
  128. }
  129. else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == true)
  130. {
  131. //Call a browse files dialog box & intialize variables
  132. string strFileLocation = "";
  133. string strDirectory = @"C:\Users\Administrator\Desktop";
  134. //Save File
  135. SaveFileDialog saveFile = new SaveFileDialog();
  136. // Default file extension
  137. saveFile.DefaultExt = "docx";
  138. saveFile.FileName = ExcelApp.ActiveWorkbook.Name;
  139. // Available file extensions
  140. saveFile.Filter = "Doc Files (*.doc, *.docx)|Excel Files (*.xls, *.xlsx)|Adobe Files (*.pdf)|Image Files (*.jpg," + "*.jpeg,*.bmp, *.tiff, *.giff, *.png)" + "|All files (*.*)|*.*";
  141. saveFile.Filter = "All files (*.*)|*.*";
  142. saveFile.FilterIndex = 1;
  143. // Adds a extension if the user does not
  144. saveFile.AddExtension = true;
  145. // Restores the selected directory, next time
  146. saveFile.RestoreDirectory = true;
  147. // Dialog title
  148. saveFile.Title = "Where do you want to save the file?";
  149. saveFile.OverwritePrompt = true;
  150. // Startup directory
  151. saveFile.InitialDirectory = strDirectory;
  152. // Show the dialog and process the result selectedFileRowIndex,sLFVerName_global,sLFVerID_global
  153. if (saveFile.ShowDialog() == DialogResult.OK)
  154. {
  155. strFileLocation = saveFile.FileName;
  156. //fileName = saveFile.SafeFileName;
  157. object missing = Type.Missing;
  158. ExcelApp.ActiveWorkbook.SaveAs(Filename: strFileLocation);
  159. frmSelectFolder frmSelectFolder = new frmSelectFolder();
  160. frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
  161. frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
  162. frmSelectFolder.ShowDialog();
  163. e.Cancel = true;
  164. }
  165. else
  166. e.Cancel = true;
  167. }
  168. else
  169. return;
  170. }
  171. catch (Exception ex)
  172. {
  173. MessageBox.Show(ex.Message);
  174. }
  175. }
  176. }
  177. else
  178. {
  179. try
  180. {
  181. if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == false)
  182. {
  183. ExcelApp.ActiveWorkbook.Save();
  184. }
  185. else if (!ExcelApp.ActiveWorkbook.Saved && e.SaveAsUI == true)
  186. {
  187. //Call a browse files dialog box & intialize variables
  188. string strFileLocation = "";
  189. string strDirectory = @"C:\Users\Administrator\Desktop";
  190. //Save File
  191. SaveFileDialog saveFile = new SaveFileDialog();
  192. // Default file extension
  193. saveFile.DefaultExt = "xlsx";
  194. saveFile.FileName = ExcelApp.ActiveWorkbook.Name;
  195. // Available file extensions
  196. saveFile.Filter = "Excel Files (*.xls, *.xlsx)|Doc Files (*.doc, *.docx)|Adobe Files (*.pdf)|Image Files (*.jpg," + "*.jpeg,*.bmp, *.tiff, *.giff, *.png)" + "|All files (*.*)|*.*";
  197. saveFile.Filter = "All files (*.*)|*.*";
  198. saveFile.FilterIndex = 1;
  199. // Adds a extension if the user does not
  200. saveFile.AddExtension = true;
  201. // Restores the selected directory, next time
  202. saveFile.RestoreDirectory = true;
  203. // Dialog title
  204. saveFile.Title = "Where do you want to save the file?";
  205. saveFile.OverwritePrompt = true;
  206. // Startup directory
  207. saveFile.InitialDirectory = strDirectory;
  208. // Show the dialog and process the result selectedFileRowIndex,sLFVerName_global,sLFVerID_global
  209. if (saveFile.ShowDialog() == DialogResult.OK)
  210. {
  211. strFileLocation = saveFile.FileName;
  212. //fileName = saveFile.SafeFileName;
  213. object missing = Type.Missing;
  214. ExcelApp.ActiveWorkbook.SaveAs(Filename: strFileLocation);
  215. frmSelectFolder frmSelectFolder = new frmSelectFolder();
  216. frmSelectFolder.selectedLocalFilePath = ExcelApp.ActiveWorkbook.Path + "\\" + ExcelApp.ActiveWorkbook.Name;
  217. frmSelectFolder.selectedLocalFileName = ExcelApp.ActiveWorkbook.Name;
  218. frmSelectFolder.ShowDialog();
  219. e.Cancel = true;
  220. }
  221. else
  222. e.Cancel = true;
  223. }
  224. else
  225. return;
  226. }
  227. catch (Exception ex)
  228. {
  229. MessageBox.Show(ex.Message);
  230. }
  231. }
  232. }
  233. catch (Exception ex)
  234. {
  235. MessageBox.Show(ex.Message);
  236. }
  237. }
  238. }
Add Comment
Please, Sign In to add comment