Advertisement
Willcode4cash

Read hyperlinks from MS Word file

Sep 22nd, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. var application = new Application();
  2. object missing = Type.Missing;
  3. object filename = "c:\\data\\sample.docx";
  4. object False = false;
  5. application.DisplayAlerts = WdAlertLevel.wdAlertsNone;
  6.  
  7. Document document = application.Documents.Open(
  8.     ref filename, ref missing, ref missing, ref missing,
  9.     ref missing, ref missing, ref missing, ref missing, ref missing,
  10.     ref missing, ref missing, ref False, ref missing, ref missing,
  11.     ref missing, ref missing);
  12. Hyperlinks links = document.Hyperlinks;
  13.  
  14. for (int i = 1; i <= links.Count; i++)
  15. {
  16.     object index = i;
  17.     Hyperlink link = links.get_Item(ref index);
  18.     link.Address = "http://www.google.com";
  19. }
  20.  
  21. if(document != null)
  22. {
  23.     try
  24.     {
  25.         document.Save();
  26.     }
  27.     catch {}
  28.     document.Close(ref missing, ref missing, ref missing);
  29. }
  30.  
  31. if (application != null) application.Quit(ref missing, ref missing, ref missing);
  32.  
  33. GC.Collect();
  34. GC.WaitForPendingFinalizers();
  35. GC.Collect();
  36. GC.WaitForPendingFinalizers();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement