Question

I have a Web application. It sends a series of images to the server (no problem there) and then uses code from this tutorial to create a PowerPoint presentation. The presentation is saved in a directory on the web server and the URL is returned to the user.

However, the file is still in use and attempting to access it generates a 500.0 error in IIS 7.5.

If I open the task manager and kill the w3wp.exe process that belongs to the NETWORK SERVICE user everything works as intended (the file can be downloaded and viewed). I also have another w3wp process belonging to DefaultAppPool, but it doesn't seem to cause a problem.

I'm new to this .Net coding, so it is very possible I forgot to close something down in code. Any ideas?

Edit: This is the method that creates a series of png's from image data that is encoded into a string. It uses a Guid to create a unique bit of a directory path, and checks to make sure it doesn't exist and then creates the directory and places the images there.

It looks like the offending method is this one:

So the offending method is this one:

    public void createImages(List<String> imageStrings)
    {
        UTF8Encoding encoding = new UTF8Encoding();
        Decoder decoder = encoding.GetDecoder();

        Guid id = Guid.NewGuid();
        String idString = id.ToString().Substring(0, 8);

        while (Directory.Exists(imageStorageRoot + idString))
        {
            id = Guid.NewGuid();
            idString = id.ToString().Substring(0, 8);
        }

        String imageDirectoryPath = imageStorageRoot + idString + "\\";
        DirectoryInfo imagePathInfo = Directory.CreateDirectory(imageDirectoryPath);

        for (int i = 0; i < imageStrings.Count; i++)
        {
            String imageString = imageStrings[i];
            Byte[] binary = Convert.FromBase64String(imageString);

            using (FileStream stream = new FileStream(imageDirectoryPath + idString + i.ToString() + ".png", FileMode.Create))
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(binary);
                }
            }
        }
    }

Edit 2: If there is a better to about doing things please let me know. I am trying to learn here!

Edit 3: So upon further examination, I can comment out all this code. In fact, the second instance of w3wp.exe starts up as soon as a browser hits the website. I am now wondering if this might have something else to do with our stack? Its a Flex app, that uses WebOrb for remoting to some C# classes.

Does anyone know why this second open instance of w3wp.exe (owned by NETWORK SERVICE) would prevent the file from opening properly? Is there some way to get it release it's hold on the file in question?

No correct solution

OTHER TIPS

Make sure you've closed the file after using it (better yet put the code that accesses your files in using statements). Post some code if you need help figuring out where the issue is.

The sample looks good. Did you deviate from the code structure?

 using (Package pptPackage = 
    Package.Open(fileName, FileMode.Open, FileAccess.ReadWrite))
  {
       // your code goes inside there
  }

If your code does contain the using statement you should be fine. If not add a Dispose call to your Package object when you are done or you will leave the file open for a long time until (possibly) the finalizer will kill it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top