Instead you have to use a VB ScriptingFileSystemObject in C#. C# doesnt have it by default. So you have to add the Microsoft VisualBasic.dll to your references in your c# project.
After that you can relink your Indesign graphics like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InDesignServer.Objects allGraphics = this.document.AllGraphics;//your indd document | |
this.basePath = "C:/myimages/"; | |
foreach (dynamic graphic in allGraphics) | |
{ | |
InDesignServer.Link link = graphic.ItemLink; | |
string path = link.FilePath; | |
string fileName = this.basePath + "/" + link.Name; | |
object fileSystemObject = Microsoft.VisualBasic.Interaction.CreateObject("Scripting.FileSystemObject", ""); | |
Type fileSystemObjectType = Type.GetTypeFromProgID("Scripting.FileSystemObject"); | |
object file = fileSystemObjectType.InvokeMember("GetFile", System.Reflection.BindingFlags.InvokeMethod, null, fileSystemObject, new object[] { path }); | |
link.Relink(file); | |
link.Update(); | |
} |