سؤال

I'm requesting assistance in using code that's worked for me on a .NET web application and now trying to run it as a Module .exe on the server. I know why it's not working, I just don't know the syntax to get it working correctly.

Previously, I had an app run inside a folder on the web server /ms/xml/test.xml I would reference this file by using Server.MapPath such as this:

myXMLDoc = New XmlDocument

myXMLDoc.Load(Server.MapPath("test.xml"))

Now I am trying to use this code on a Module .exe file that resides on the C: drive of the server and will be added to the Task Scheduler.

I'm not sure how I reference this file now that it is on an extra hard drive. Our web server is on the D: drive. We are running Windows 2012. This .exe file is on the C: drive.

هل كانت مفيدة؟

المحلول

Just use the literal path:

myXMLDoc.Load("C:\SomeDir\SomeFile.xml)

Server.MapPath is just used when you don't know what the root folder of your web server is. Is you are reading/writing to a fixed location you can just specify the actual path.

Your biggest problem is likely to be permissions so make sure the process your asp.net application is running under has permission to read (and possible write)to the location you want to use

And don't forget that UAC will prevent read/write from certain locations (such as the root of the C: drive)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top