Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2007, 04:58 PM
deepquiet25
Guest
 
Posts: n/a
Default Search a file on my server

Hello!

Sorry, I'm spanish, and I don't speak english very well.

I want to search a file in one of the folders of my ASP.NET WebSite. I'm using c# and I want to search the file.

I used
string[] t = Directory.GetDirectories("\\ArchAudio");

but I don't know how to set my web server like the root directory.
If I use Directory.SetCurrentDirectory("~"); it fails

Somebody could help me?

Thank you!

 
Old August 28th, 2007, 07:16 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can resolve ~ to the physical path with this:

Server.MapPath("~")

Then you can use that physical path in the System.IO class methods.

-Peter
 
Old August 28th, 2007, 07:35 PM
deepquiet25
Guest
 
Posts: n/a
Default

If I do this Server.MapPath("~");

the directory will be D:\ and I want the root of my webSite

D:\code\WebSite

 
Old August 28th, 2007, 09:26 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'm not sure I understand.

~ resolves to the root of the web application. This is not what you want?

Please post the real directory paths of you web app and desired path so we can see the relationship to better understand what you want.

Perhaps I don't understand what you meant by "but I don't know how to set my web server like the root directory."

-Peter
 
Old August 29th, 2007, 01:11 AM
deepquiet25
Guest
 
Posts: n/a
Default

not exactly.

My web is (for example) D:\code\WebSite I consider the root of my website this directory, and I want that my code runs also in another computers if change my website to another computer, because if I write the "d:\code\website" it will fail. Do you understand to me ?

Sorry, because my english is very poor

thanks

 
Old August 29th, 2007, 02:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In that case, the code that Peter suggested should work.

string myRoot = Server.MapPath("~/");

should give you something like D:\code\WebSite

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
File Search ybg1 Access 2 October 10th, 2007 02:09 AM
I need search a file on my server deepquiet25 ASP.NET 1.0 and 1.1 Basics 0 August 28th, 2007 05:07 PM
Regarding search in SQL SERVER 2005 comvidyarthi SQL Language 0 March 27th, 2007 09:35 AM
File Search / Indexing Search with .net 2.0 maulik77 ASP.NET 1.0 and 1.1 Basics 2 March 15th, 2007 12:45 AM
Search for a particular file snowydust VB How-To 0 July 19th, 2004 05:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.