Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if a file exists in server 1

Status
Not open for further replies.

bclt

Programmer
Joined
Mar 13, 2005
Messages
363
Location
GR
Hi,

I have a web app in "c:\inetpub\ or "
I want to check if is there is a file in ".../web1/fff/5.txt"

I tried this:

Code:
imports system.io

Label1.Text = File.Exists("./fff/5.txt")

but the label's text is always false! What is wrong

Tnx
 
Use
Dim myFile as String = Server.MapPath("yourFileHere")
Label1.Text = File.Exists(myFile).ToString()

System.IO wants to see C:\Inetpub\
This blurb is from Microsoft:
In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:

"c:\\MyDir\\MyFile.txt" in C#, or "c:\MyDir\MyFile.txt" in Visual Basic.
"c:\\MyDir" in C#, or "c:\MyDir" in Visual Basic.
"MyDir\\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic.
"\\\\MyServer\\MyShare" in C#, or "\\MyServer\MyShare" in Visual Basic.
 
Thanks Veep, it works.

Let me ask you something more. How can i have access to the server (permittion better) to create a txt file?
I want to write some data in it and the close it.

I think if i write file.create(...) there will be error
 
Is this a company Intranet, Hosting Provider or your own machine? You'll need to make sure that the {Machine_Name}\ASP.NET & IUSR_Machine_Name accounts have permissions to do a "write" on a particular folder.

On a company intranet you may have to ask web site support (or whoever) to do this for you.

If it's a (good) hosting provider you should be able to do this yourself via their admin console. If not, then you'll have to ask them.

If it's your own box then you can do it yourself.
 
I am talking about a webapp that will do some IO (create text files). I first will see if it works in my pc (c:\inetpub\ Then I have a puprose of buying a web host and copy there my app.
 
Well then, follow the steps above. If you need to know how to set permissions on folders on your machine then let me know. I'd be glad to help.
 
Thanks Veep,that is what i want to do; set permissions (create text files) to a folder. Will you help me?

I suppose that when i copy the app in my web site I'll have permission to create texts in e.g "./folder/
 
Right-click on the folder that you want to write to.
Select <Properties> and then the <Security> tab.
Click the <Add> button.
From the list add ASPNET and IUSR_[YourMachineName].
After you've added them click <OK>.
Then, back on the <Security> tab check <Allow> for Read, Write and Modify.
That's it!

Here's a brief tutorial on how to create text files with ASP.NET...
 
There is no security tab :(
There is only "general", "sharing", "web sharing" and "cystomize"

You mean right click on the folder in my pc (c:\intepub\...)?
 
What OS are you using, XP Pro?

To reveal the Security tab, open Windows Explorer, and choose Folder Options from the Tools menu. On the View tab, scroll to the bottom of the Advanced Settings and clear (click) the check box next to "Use Simple File Sharing." Click OK to apply the change, and you should now have a Security tab when viewing the properties of a file on an NTFS volume.

Then:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top