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

  • Home
  • SEARCH
  • 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 7084095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:15:33+00:00 2026-05-28T07:15:33+00:00

I have a service that reads an xml document from a directory(works OK), saves

  • 0

I have a service that reads an xml document from a directory(works OK), saves the data in sql (works OK) and after that I am copying the file to a FINISHED directory (works OK) and deleting the file (NOT working)from the reading directory. The PROBLEM that I have is that the file is being locked when I try to execute the DELETE. Any advise will be appreciated so I can find where the file is being locked.

static public Res GetResMn(string FileName)             
XDocument root = null;
using (var file = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            using (StreamReader oReader = new StreamReader(file, Encoding.GetEncoding("ISO-8859-1")))
            {
                root = XDocument.Load(oReader);
                oReader.Close();
                oReader.Dispose();
            }

Here is the code for the copy and delete

    void CopyFile(string FileToMove, string MoveLocation)
    {
        try
        {
             System.IO.File.Copy(FileToMove, MoveLocation, true);
            //System.IO.File.Move(FileToMove, MoveLocation);

                File.Delete(FileToMove);
        }
        catch (Exception e)
        {
            WriteLogFile("The process failed: {0} " + e.ToString());
        }
    }

This is the code when I get the values from the file

    var myElement1 = root.Descendants(XName.Get("rnID", @"namespace.2.0")).FirstOrDefault();
    if (myElement1 != null)
    {
        myRPr.rnID = root.Descendants(XName.Get("rnID", @"namespace.2.0")).FirstOrDefault().Value;
    }

This is the error that I am getting in my logFile

{0} System.UnauthorizedAccessException: Access to the path 'C:\ReadingDirectory\FileName.xml' is denied.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.Delete(String path)
    at OperaWinSrvc.OperaWinSrvc.ReadFiles()

I am gettign the same kind of error when I tried the
System.IO.File.Move

  • 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-28T07:15:33+00:00Added an answer on May 28, 2026 at 7:15 am

    After doing multiple check ups in different places I finally found the solution to my problem. In the service installer I had the Account property set to Local Service, I change it to LocalSystem, reinstall the service and it appears to work now.

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

Sidebar

Related Questions

I have a page with a datatable that reads data from a service class.
I have a WCF service library that reads a xml file that's located in
I have a service application that on startup reads an XML file and starts
I have an service application that reads a config file containing a list of
Let's say I have to read from a directory that has many large XML
I'm developing an application that reads data from a SQL server database (migrated from
I have a .NET web-service client that has been autogenerated from a wsdl-file using
I am attempting to create a web service that reads an xml file and
I have a program that reads an XML file (for now, on local computer.)
I created simple web service with Jersey that reads in an XML file and

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.