7 Replies Latest reply on Dec 28, 2012 5:29 AM by Gozoliet2

    [CS5][vb.net]  Relink problem

    Dean Kroon



      I'm trying to relink grapics in CS5 with vb.net.  This was easy from CS3 where you simply coded something like   img.ItemLink.Relink("C:\img.jpg").  Now when I do this same code (which worked fine for years), I get the error "{"Cannot create the link resource from the given URI."}".



      Has anyone got relink to work in CS5 from any of the .NET languages?  This is a deal-killer for moving my corporation from CS3 to CS5.




        • 1. Re: [CS5][vb.net]  Relink problem



          a really ugly workaround is the following.


          Suppose myIdApp is a reference to the InDesign application.

          Suppose we want to relink the third link in the active document.

          Then we could write:




          However, this doesn't work, as you already noted.

          Instead we can write:


          Dim myResult as Variant

          myResult = myIdApp.DoScript("app.activeDocument.links.item(2).relink(new File(""C:\\Temp\\Test.jpg""))", idJavascript)


          This does the relink from the JavaScript engine built into InDesign.


          Note the following Points.


          * Instead of the index 3 in Links(3), we use the index 2 in links.item(2) since VB uses index base 1 and JavaScript uses index base 0.


          * The file object created with new File() is a JavaScript file object. This is accepted by relink() as a valid argument.

          I tried using a VB file object obtained from FileSystemObject.GetFile() as an argument in the VB call Links(3).Relink().

          But this didn't work.


          * All the \ in the file path must be escaped to \\ since the first argument of DoScript() is JavaScript source code.


          I tried various other things, but this is the only one that worked for me.


          Hope that helps.

          • 2. Re: [CS5][vb.net]  Relink problem
            S.M. Arafat



            I'm having the same problem when relinking. I'm using the following environment:


            1. InDesign CS5 Server

            2. C#


            And I tried with the following code:

            string script = "app.documents[0].links.item(1).relink(new File(" + "\"C:\\Temp\\Test.jpg\"))";


            But when I run the application it gives me the following error:

            System.Runtime.InteropServices.COMException (0x00007306): Either the file does not exist, you do not have permission, or the file may be in use by another application


            But I've checked that the file exists and no one is using the file.


            I'm in trouble with this, any help will be highly appreciated.


            Best Regards,

            • 3. Re: [CS5][vb.net]  Relink problem
              S.M. Arafat Level 1

              Finally my problem is fixed :-)


              It was the problem in my script. Now I've written the script this way and worked.


              string script = @"app.documents.item(0).links.item(1).relink(new File(""C:\\Temp\\Test.jpg""))";





              • 4. Re: [CS5][vb.net]  Relink problem
                Tony Tuneson Level 1

                Just encountered the same bug (?). Is there already a better solution then thementioned  JavaScript workaround?

                • 5. Re: [CS5][vb.net]  Relink problem

                  Since I stumbled on this thread with the same error, here's my fix.


                  InDesign is looking for a URI (file://c/temp/test.jpg")


                  So, instead of:




                  you could do:


                  myIdApp.ActiveDocument.Links(3).Relink(new uri("C:\Temp\Test.jpg").tostring)


                  (or any other way you prefer to use the Uri objects)

                  • 6. Re: [CS5][vb.net]  Relink problem
                    Tony Tuneson Level 1

                    Thanks for sharing, I'll try it first thing next year! Just curious: how did you find this out? Is it documented somewhere?

                    • 7. Re: [CS5][vb.net]  Relink problem
                      Gozoliet2 Level 1

                      Experience? Luck?


                      There wasn't much to find in the quick google search I used.  The help files I refer (I use a downloaded copy of Jongware's HTML files http://jongware.mit.edu/idcs5js/) just mention String.  The error message "Cannot create the link resource from the given URI." in hindsight was a pretty big hint that I should send it a URI.