automatically copy data file to root directory, asp.net

A

Arthur

hi,

this might be a simple one to them who know:

i'm developing an asp.net project and use the debug mode. i have a xml
file which contains data, that shall be read, if a specific page is
run. when i build the project the file is correctly copied to the
build location (i selected "build action: none" and "copy if newer").
but when the project is run, the xml file is missing at the directory
from which the site is executed. it does not get copied there
automatically. in my case the directory where the site is executed is

"c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\"

what do i have to do, so the file is available in the the directory
where the site is executed at execution time?

thanks in advance,
arthur
 
J

Juan T. Llibre

re:
!> what do i have to do, so the file is available in the
!> directory where the site is executed at execution time?

Is there anything stopping you from using the
App_Data folder to store your application's XML data ?

It's much safer than storing an XML file in the root directory, anyway, since XML files
in the App_Data directory are not served to clients, even if requested directly.

If you store your XML files in the App_Data directory, all you have to do is
check the "Include files from the App_Data folder" option when publishing your website.

VS will upload your XML data files to the App_Data directory.
 
A

Arthur

Hi,

thanks for your answers.

@juan & mark:

i put the file in the App_Data folder. now the folder gets copied to
the build location on compilation, but is still not available when
running the project on the local computer in debug mode. its just the
exception message changed from "file not found" to "folder not found".

@patrice:

it must be a webproject as it starts a local server and iexplorer to
view the site.


lets put it that way:
how would you add a content file, you want to read from a class that
is implemented in one of your websites? it should be in the project or
App_Data folder, i want to edit it there and it shall be avail at
runtime, when testing in debug mode on an local instance of iis. you
are surely not going to publish the whole site everytime you want to
test it while devloping, are you?

eg:
page_load in index.aspx.cs wants to open file "App_Data\content.xml"
and read from it.

what do i have to do, that "content.xml" is available in whatever
directory, the site is copied to, when running it locally by pressing
F5?

this has to be easy! - lol - if not, its typically microsoft :)
 
J

Juan T. Llibre

re:
!> how would you add a content file, you want to read from
!> a class that is implemented in one of your websites?

DataSet mydata = new DataSet();
mydata.ReadXml(Server.MapPath("~/App_Data/content.xml"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top