automatically copy data file to root directory, asp.net

  • Thread starter Thread starter Arthur
  • Start date Start date
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
 
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.





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
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 :-)
 
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"));



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
Back
Top