1 Reply Latest reply on Mar 20, 2009 9:14 PM by GLeizerowicz

    Using pdi files as embedded resources with ActiveView


      I'm trying to use ActiveView to view a PDI file that is an embedded resource in C# project in Visual Studio 2008. Is there any way to set the DisplayURL property using a relative path to the embedded pdi file?


      Alternatively, is there a way to determine the path of an embedded resource?

        • Re: Using pdi files as embedded resources with ActiveView

          Hi James -


          One alternative is to write the embedded resource to a temporary location on disk, then pass that path to the ActiveView control using the DisplayURL property.  You can delete the file when you're done with it, based on the needs of your application.  The following code writes an embedded display to local storage, then sets the DisplayURL property to that path:


          using System.IO;
          using System.Reflection;

          string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "embedded.pdi");
          string resourceName = "EmbeddedResource.embedded.pdi";

          using (FileStream fileStream = File.OpenWrite(path))
          using (Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
              int bytesRead = 0;
              int bufferSize = (int)Math.Pow(2, 10);
              byte[] buffer = new byte[bufferSize];
              while (0 < (bytesRead = resourceStream.Read(buffer, 0, bufferSize)))
                  fileStream.Write(buffer, 0, bytesRead);


          activeViewControl.DisplayURL = path;

          For the sake of other readers who may not be familiar with embedded resources - the resourceName property may not be what you expect.  This code is based on a resource that was embedded at the root of the project and therefore uses the root namespace of the project.  If you are unsure what the full name of the resource will be at runtime, use the Assembly.GetManifestResourceNames method to get a list of names that you can pass to the GetManifestResourceStream method.


          Just curious - have you weighed other methods of deploying your displays such as central file storage or on a web server that can be reached by your application?