Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / March 2007

Tip: Looking for answers? Try searching our database.

How do you programmatically create a file in the App_Data folder?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony Girgenti - 28 Mar 2007 17:59 GMT
Hello.

Developing a web site in VS2005, SP1, VB, .NET 2.0, ASP.NET 2.0 on XP Pro,
SP2.

I'm trying to write a file to the App_Data folder in my project using:

       Dim docPath As String = "~\App_Data\Trips.xml"
       Using sw As StreamWriter = File.CreateText(docPath)
           sw.WriteLine(doc.InnerXml)
           sw.Close()
       End Using

It gives me an exception as:
System.IO.DirectoryNotFoundException = {"Could not find a part of the path
'C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\~\App_Data\Trips.xml'."}

I tried "\App_Data\Trips.xml", "App_Data\Trips.xml", "~App_Data\Trips.xml".

Any help would be gratefully appreciated.

Thanks,
Tony
Tony Girgenti - 28 Mar 2007 19:42 GMT
One thing i forgot to add.  It works fine if i use "C:\TRIPS.XML".

I need to know how to put it in the App_Data folder in my project.

Thanks,
Tony

> Hello.
>
[quoted text clipped - 21 lines]
> Thanks,
> Tony
Jim Hughes - 29 Mar 2007 05:09 GMT
Try using

Dim docPath As String = Server.MapPath(".") & "\App_Data\Trips.xml"

> One thing i forgot to add.  It works fine if i use "C:\TRIPS.XML".
>
[quoted text clipped - 28 lines]
>> Thanks,
>> Tony
Tony Girgenti - 29 Mar 2007 19:44 GMT
Hello Jim.

Thanks for that info.  That worked, but i had to use Server.MapPath(".."),
because my web page for this part of the website is in a seperate folder.  I
have all of my web pages in seperate folders by category.

How do i use the MapPath to start at the root of my website so that i can
get to the App_Data folder programmatically from wherever i'm at in the
folder structure?

Thanks,
Tony

> Try using
>
[quoted text clipped - 32 lines]
>>> Thanks,
>>> Tony
Rory Becker - 29 Mar 2007 19:53 GMT
> Hello Jim.
>
[quoted text clipped - 6 lines]
> can get to the App_Data folder programmatically from wherever i'm at
> in the folder structure?

If memory serves, MapPath("~") will start at the web application level

Thus MapPath("~/MyFolder") should get "MyFolder" in the current WebApp

--
Rory
Tony Girgenti - 29 Mar 2007 20:14 GMT
Hello Rory.

That worked.  Excellent.

But shouldn't
"Dim docPath As String = "~\App_Data\Trips.xml"

work the same as
"Dim docPath As String = Server.MapPath("~") & "\App_Data\Trips.xml" ?

Thanks,
Tony

>> Hello Jim.
>>
[quoted text clipped - 13 lines]
> --
> Rory
Rory Becker - 29 Mar 2007 20:28 GMT
> That worked.  Excellent.
>
> But shouldn't
> "Dim docPath As String = "~\App_Data\Trips.xml"
> work the same as
> "Dim docPath As String = Server.MapPath("~") & "\App_Data\Trips.xml" ?

From...

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_aspnetcon/html/2447f50c-b849-483c-8093-85ed53e7a5bd.htm

..."The ~ operator is recognized only for server controls and in server code.
You cannot use the ~ operator for client elements."

So basically the ASP.Net side (server side) of things will understand "~"
because it will internally call MapPath.

You can use it as the SRC for an image on a serverside control and the system
will translate nicely.

However don't try to save files to "~\SomeDir\Somefile.ext" using just basic
file io, as the system will not understand what you're talking about.

MapPath is used to translate in just such occassions.

It might be worth double checking this information as it is some time since
I've worked in this area :)

Now that I finally have a copy of VS2005 I might have to dive back in and
have some fun with master pages etc :) (So much stuff to play with, So little
time :))

--
Rory

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.