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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading File From Server 1

Status
Not open for further replies.

arpan

Programmer
Joined
Oct 16, 2002
Messages
336
Location
IN
Consider the following code snippet:
Code:
<%
  Dim objFSO,objOpenFile,strPath
  strPath=Server.MapPath(&quot;ADList1.txt&quot;)
  Set objFSO=Server.CreateObject (&quot;Scripting.FileSystemObject&quot;)
  Set objOpenFile=objFSO.OpenTextFile(strPath,1)
  Do While Not objOpenFile.AtEndOfStream
     Response.Write(objOpenFile.ReadLine() & &quot;<br>&quot;)
  Loop
  objOpenFile.Close
  Set objOpenFile=Nothing
  Set objFSO=Nothing
%>
When I try to execute the above code, the code never gets executed. Neither am I shown a script timeout error. After a lot of investigations, I concluded that the code is not getting executed due to the presence of

Set objOpenFile=objFSO.OpenTextFile(strPath,1)

If I comment line nos. 5 to 10, then the code gets executed but as expected without any output. Is this happening because of some permission which has not been given to IIS 5.0? If so, what is it? I am working on Windows 2000 Pro.

Thanks,

Arpan
 
onlyt hing I can see is;
Set objFSO=Server.CreateObject (&quot;Scripting.FileSystemObject&quot;)

The space right after Server.CreateObject

Other than that looks fine. If you Response.Write strPath what does is write?
 
Hi spazman,

Thanks for your advice but I am afraid that the presence of a space between Server.CreateObject & (&quot;Scripting.....&quot;) does not make any difference. I have tried it out. Response.Write(strPath) gives the output as

c:\inetpub\
I have got a strong feeling that this is happening because of some permission which has not been assigned to IIS. Any other suggestions????

Regards,

Arpan
 
The MapPath piece may be what's causing your problem. Try this:

<%
Dim objFSO,objOpenFile,strPath
Set objFSO=Server.CreateObject (&quot;Scripting.FileSystemObject&quot;)
Set objOpenFile=objFSO.OpenTextFile(&quot;ADList1.txt&quot;,1)
Do While Not objOpenFile.AtEndOfStream
Response.Write objOpenFile.ReadLine & &quot;<br>&quot;
Loop
objOpenFile.Close
Set objOpenFile=Nothing
Set objFSO=Nothing
%>


TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
No, my dear TwoOdd, that's not the reason. I tried it out only to encounter the exactly same problem. Any other suggestions????

Thanks,

Regards,

Arpan
 
You've probably already tried this, but if not try hard coding the path.

For example:
Set objOpenFile=objFSO.OpenTextFile(&quot;C:\temp\ADList1.txt&quot;,1)

You might try putting the file in c:\temp\ and set the permissions on that folder and then test the webpage to make sure you can read the text file from there.

The code itself looks fine to me, so I'm not sure where else to point you.

Good luck,





TwoOdd
--------------
Good judgment comes from experience, and experience comes from bad judgment.
-- Barry LePatner
 
If you have Anonymous access checked for your web site then you are using the IUSR_yourmachinename user to access the file. Give him permissions to the directory the file is in.
If you have Integrated Windows Authentication checked and Anonymous access unchecked then give the user who is accessing the site access to the directory the file is in.

The code works on my 2000 box.
 
Yes,Sarkman,I have Anonymous access checked for my website using IUSR_ARPAN (where ARPAN is my machinename). How do I give him (him means IUSR_ARPAN, isn't it?) permissions to the directory the file is in? Also what do you mean by &quot;file&quot;? Is it the txt file which I am trying to read or is it the ASP file which is trying to read the txt file?

Also I have Integrated Windows Authentication & Anonymous Access checked under Authentication Methods.

Thanks,

Regards,

Arpan
 
the file is the txt file.

go to the folder on the web server and right click, select properties and then click on the security tab. Add IUSR_ARPAN to the security in that folder. Try full control first to see if it works. If it does then you can give him only the permissions he needs to access the file.

If you have both Integrated Windows Authentication & Anonymous Access then you should be using IUSR_ARPAN to access the txt file.
 
I went to the folder in the web server and right-clicked, selected 'Properties', went to the 'Directory Security' tab, clicked the 'Edit' button under 'Anonymous Access & Authentication Control'. This pops up a dialog box titled 'Authentication Methods' (in which 'Anonymous Access' & 'Integrated Windows Authentication' checkboxes are checked), then clicked the 'Edit' button under the 'Anonymous access' checkbox. Next I am shown a dialog box titled 'Anonymous User Account' in which the Username is given as IUSR_ARPAN, the Password textbox is disabled & the 'Allow IIS to control password' checkbox is checked. I hope I have done everything correctly. But still I am not able to read the txt file. In fact, all the folders within inetpub\ have IUSR_ARPAN as the username. Where am I going wrong?

If you go to 'Control Panel' in Windows 2000, click 'Users & Passwords', a dialog box opens up with the title 'Users and Passwords'. Under the 'Users' tab, I can see that one of the User Names given is IUSR_ARPAN which falls under the 'Administrators' Group. Are any changes required here? I have no idea......that's why I am asking you.

Thanks,

Regards,

Arpan
 
I think you went through the computer management MMC.
GO to the physical location of the folder (i.e. C:\inetpub\
Right click on the folder and select properties and follow the instructions previously
 
But I don't find any 'Security' tab when I click Properties. It shows only 2 tabs - General & Web Sharing. Under the 'Web Sharing' tab, the 'Do not share this folder' radio button is checked.
 
I'm guessing you may not have the appropiate permissions on the web server to change security.
Some security policies remove the security tab. Get an admin to set the permissions on the web server for you.
 
But I myself am the admin!! How do I set the permissions on the web server? I am using the FAT file system. Could this be the reason why the 'Security' tab is not visible? I guess using NTFS as the file system may show the 'Security' tab.........not sure though........

Could you please please please give a concrete solution for this problem? This is driving me crazy. Since last 2 days, I am trying to get a solution but all my efforts & time has gone in vain & down the drain. I know you have been trying your level best to pull me out of this mess for which I am highly grateful to you.

Arpan
 
that is the reason. the security tab is only available if you are using NTFS.
 
Try creating a share on the folder and give permissions to IUSR_ARPAN.
 
Actually due to some unavoidable reasons, I had to re-install Win2K Pro & this problem started only after the re-installation. I didn't face any such problems prior to the re-installation when I used to work with FAT & everything went off smoothly. Then what could the problem be now????

Arpan
 
Hi Sarkman, you will be happy to know that I have got the solution. You know who was the culprit? Maybe you won't believe me but the culprit was Norton Anti-Virus!!! Have a look at the following URL That will answer all the questions!!!

Last but not the least, I would like to thank you once again from the bottom of my heart for all the help & support you have given me.

Thanks,

Regards,

Arpan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top