Accessing Files In 'App_Data' Folder

J

Joey

asp.net 2/C#/VS2005

I have a web app where I use a stream writer to create a CSV (text)
file. I then use my code to save the file in the site's 'App_Data'
folder, in a subfolder called 'Temp'. Finally, I redirect the page to
that file in order to serve it out (push the download) to the user.
This all worked great in .net v1.1.

Now, in my new .net v2 app, everytime the page redirect occurs, the
browser displays "The webpage cannot be found." I have verified that
the file is located in 'App_Data' folder. I have also verified that
the redirect is going to the correct URL. I even tried manually typing
the URL ("http://localhost/App_Data/Temp/MyFile.csv") into the browser
- same result.

I also thought this problem might be occurring due to IIS not having a
mapping for the CSV filetype, so went to the IIS snap in and added it.
I basically used the same aspnet DLL file and verbs as for the aspx
pages. After stopping and restarting the site, it still gives the "The
webpage cannot be found" message.

What can I do to make this work?
 
L

Larry Bud

asp.net 2/C#/VS2005

I have a web app where I use a stream writer to create a CSV (text)
file. I then use my code to save the file in the site's 'App_Data'
folder, in a subfolder called 'Temp'. Finally, I redirect the page to
that file in order to serve it out (push the download) to the user.
This all worked great in .net v1.1.

Now, in my new .net v2 app, everytime the page redirect occurs, the
browser displays "The webpage cannot be found." I have verified that
the file is located in 'App_Data' folder. I have also verified that
the redirect is going to the correct URL. I even tried manually typing
the URL ("http://localhost/App_Data/Temp/MyFile.csv") into the browser
- same result.

I also thought this problem might be occurring due to IIS not having a
mapping for the CSV filetype, so went to the IIS snap in and added it.
I basically used the same aspnet DLL file and verbs as for the aspx
pages. After stopping and restarting the site, it still gives the "The
webpage cannot be found" message.

What can I do to make this work?

Why are you saving into App_Data? App_Data is a system .NET folder
and those files are protected in there.

Just create a regular folder and save them in there.
 
S

sloan

I concur.

Don't use App_Data for temp files.

App_Data would have:
myaccess.mdb
myfile.xml
sqlexpressfile.db (whats the extension??)

type files in it. Not temp files.
 
J

Joey

I concur.

Don't use App_Data for temp files.

App_Data would have:
myaccess.mdb
myfile.xml
sqlexpressfile.db (whats the extension??)

type files in it. Not temp files.








- Show quoted text -

Okay, maybe I am misunderstanding something here. In the old asp.net
v1.1 app, I did just what you said. I created sub folders off of
whatever folders contained the webpages, and then I put my files in
there before redirecting to them. Like I said, that used to work
great.

Then a few weeks ago I started working with asp.net v2. When I tried
that same approach, I kept losing Session data everytime I deleted/
(and wrote?) files to those same old temp folders.

After troubleshooting this, I found out that in asp.net v2 when one
deletes/(and writes?) files/folders outside of the App_Data folder, it
causes something called an AppDomain restart - and this invalidates
all Session data. THIS IS HUGE!!!

For this reason, I started moving all of my stuff to the App_Data
folder.

So you guys are saying you have never heard about the AppDomain
restart problem before? Has anyone else heard of it?

If I can't write and delete files outside of the App_Data folder, and
I can't do it inside of the App_Data folder either, where else is
left?

Any suggestions/feedback/comments are appreciated.

Thanks,
JP
 
S

sloan

Hmm.

I see your issue and concur it is a signficant one.

However, I have deployed an app in 2.0 where I did what (we) described.

My was

/root/
/root/Reports/
/root/Reports/TempReportFiles/

and I was creating files in there. And didn't suffer the restart issue.

Are you running the built in webserver, or using IIS?

Try going to IIS and see if you get the same issues.

(Aka, you won't have mydevelpmentsite:5097/ port number thing in IIS)

Its under the project properties (to change to IIS)
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top