Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 799153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:04:52+00:00 2026-05-14T23:04:52+00:00

I have a ASP.NET SOAP web service whose web method creates a PDF file,

  • 0

I have a ASP.NET SOAP web service whose web method creates a PDF file, writes it to the “Download” directory of the applicaton, and returns the URL to the user. Code:

//Create the map images (MapPrinter) and insert them on the PDF (PagePrinter).
MemoryStream mstream = null;
FileStream fs = null;
try
{
    //Create the memorystream storing the pdf created.
    mstream = pgPrinter.GenerateMapImage();
    //Convert the memorystream to an array of bytes.
    byte[] byteArray = mstream.ToArray();
    //return byteArray;

    //Save PDF file to site's Download folder with a unique name.
    System.Text.StringBuilder sb = new System.Text.StringBuilder(Global.PhysicalDownloadPath);
    sb.Append("\\");
    string fileName = Guid.NewGuid().ToString() + ".pdf";
    sb.Append(fileName);
    string filePath = sb.ToString();
    fs = new FileStream(filePath, FileMode.CreateNew);
    fs.Write(byteArray, 0, byteArray.Length);
    string requestURI = this.Context.Request.Url.AbsoluteUri;
    string virtPath = requestURI.Remove(requestURI.IndexOf("Service.asmx")) + "Download/" + fileName;
    return virtPath;
}
catch (Exception ex)
{
    throw new Exception("An error has occurred creating the map pdf.", ex);
}
finally
{
    if (mstream != null) mstream.Close();
    if (fs != null) fs.Close();
    //Clean up resources
    if (pgPrinter != null) pgPrinter.Dispose();
}

Then in the Global.asax file of the web service, I set up a Timer in the Application_Start event listener. In the Timer’s ElapsedEvent listener I look for any files in the Download directory that are older than the Timer interval (for testing = 1 min., for deployment ~20 min.) and delete them. Code:

//Interval to check for old files (milliseconds), also set to delete files older than now minus this interval.
private static double deleteTimeInterval;
private static System.Timers.Timer timer;
//Physical path to Download folder.  Everything in this folder will be checked for deletion.
public static string PhysicalDownloadPath;

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    deleteTimeInterval = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["FileDeleteInterval"]);
    //Create timer with interval (milliseconds) whose elapse event will trigger the delete of old files
    //in the Download directory.
    timer = new System.Timers.Timer(deleteTimeInterval);
    timer.Enabled = true;
    timer.AutoReset = true;
    timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);

    PhysicalDownloadPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "Download";
}

private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
    //Delete the files older than the time interval in the Download folder.
    var folder = new System.IO.DirectoryInfo(PhysicalDownloadPath);
    System.IO.FileInfo[] files = folder.GetFiles();
    foreach (var file in files)
    {
        if (file.CreationTime < DateTime.Now.AddMilliseconds(-deleteTimeInterval))
        {
            string path = PhysicalDownloadPath + "\\" + file.Name;
            System.IO.File.Delete(path);
        }
    }
}

This works perfectly, with one exception. When I publish the web service application to inetpub\wwwroot (Windows 7, IIS7) it does not delete the old files in the Download directory. The app works perfect when I publish to IIS from a physical directory not in wwwroot. Obviously, it seems IIS places some sort of lock on files in the web root. I have tested impersonating an admin user to run the app and it still does not work. Any tips on how to circumvent the lock programmatically when in wwwroot? The client will probably want the app published to the root directory.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:04:53+00:00Added an answer on May 14, 2026 at 11:04 pm

    I forgot to come back and answer my question.

    I had to give the IIS_IUSRS group Modify permissions to the directory where I was reading/writing files.

    Thanks to all those who answered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET web service running that accepts both HTTP POST and SOAP
I have an ASP.NET application which talks to a third-party SOAP web service. My
I have an ASP.NET 4 web application that references a SOAP web service. I
I am maintaining a SOAP web service (ASP.NET version 2.0) and I have to
I have an asp.net site that uses Bing Translate Web service(http://api.microsofttranslator.com/V2/Soap.svc) The code that
I have asp.net mvc 4 web application project on my server in IIS Directory.
I have successfully created an ASP.net website to make calls to a Soap Web
This is my first time consuming a SOAP web service in ASP.Net and I
I have an ASP.NET 2.0 web service and am using it in (among other
I have an ASP.NET (1.1) web service which authenticates clients using a SoapExtension.ProcessMessage(SoapMessage) override

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.