I trying to get list of file via Classic ASP FSO companent.
But even I gave the root file permissions (IUSR_domain) from remote desktop, still I getting this error.
Microsoft VBScript runtime error '800a0046'
Permission denied
/default2.asp, line 28
<%
fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("C:\inetpub\vhosts\xx.com\httpdocs\photo\other") <-- line 28
for each x in fo.files
%>
<div id="photos">
<div class="photo"><%Response.write(x.Name & "<br>")%></div>
</div>
<%next
set fo=nothing
set fs=nothing
%>
Try using Server.MapPath
for example:
downloadFileDirectory = Server.MapPath("\httpdocs\photo\other")
Set fs= CreateObject("Scripting.FileSystemObject")
If fs.FolderExists(downloadFileDirectory) Then
Set fo= fs.GetFolder(downloadFileDirectory)
for each x in fo.files
%>etc.
set IUSR_machinename and IWAM_machinename to have change permissions for the folder.
Related
I am trying to connect to R:\database\attendanceData\ a mapped drive to be used in the following code
sDir = "R:\database\attendanceData\"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set obj_FolderBase = fso.GetFolder(sDir)
if obj_FolderBase.Files.Count = 0 then '=== Check if Attendance record data is in
response.write " No Attendance Data Found!"
response.End
end if
response.write "IT is working"
response.End
The file structure
But I get the following error
However if I move my files to C: drive, everything is working.
But it needs to be in a shared drive. Do I need to set some permission at R: or am I missing something, please help.
How do I access a value from machine.config in classic asp?
I can't find the answer anywhere....
I don't even know how to begin to try to find a solution....
Use TextStream object.
Example:
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.ReadAll)
f.Close
Set f=Nothing
Set fs=Nothing
%>
https://www.w3schools.com/asp/asp_ref_textstream.asp
We're trying to read some log files for our application but FileExists is failing in every case. So I simplified the problem with this test code:
Dim filespec, msg
filespec = Chr(34) & "C:\Windows\explorer.exe" & Chr(34)
'filespec = "C:\Windows\explorer.exe"
'filespec = Chr(34) & "C:" & Chr(34)
'filespec = "C:"
'filespec = "default.asp"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
Response.Write(msg)
As you can see, we've tried testing with and without added Chr(32) (which is the double quote character). We're testing against the file C:\Windows\explorer.exe and the file C:\Windows\explorer.exe does exist on the computer hosting the asp files and the iis server. We even fail when simply checking to see if the C drive exist.
Additionally, it even fails if we try to see if the default.asp file exists and that file is in the same directory as our filetest.asp file.
Does anyone see why our FileExists is consistently failing? Thank you.
filespec = "C:\Windows\explorer.exe"
Without the additional quotes will work. To find a folder we need to use
fso.FolderExists
Instead of FileExists.
This still doesn't find the default.asp file in the same directory. But that problem is too far removed from our actual problem which is to look at log files on another drive. That problem is too far from this original question so I'll post that problem separately.
You may want to try to load the folder in to a folder object and loop through files in the folder object. Below is an example.
Set fso = CreateObject("Scripting.FileSystemObject")
FileToFind = "explorer.exe"
FolderToSearch = "C:\Windows\"
Set myFolder = fso.GetFolder(FolderToSearch)
For each myFile in myFolder.Files
If myFile.Name = FileToFind Then
Wscript.echo "Found " & myFolder.Path & "\" & myFile.Name
End If
Next
you do not need to insert additional quotes. removing your quotes will work just fine.
Dim filespec, msg
filespec = "C:\Windows\explorer.exe"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
Response.Write(msg)
In the past, I have only noticed that you need to insert additional quotes when using the wshshell.run since a space might be interpreted as additional arguments to the filename.
It appears that our problem is not in the VBScript at all. The app is running inside an ApplicationPool in iis. The Identity property of that Application Pool is the dynamically created applicationPoolIdentity user. This is a user with no permissions. So essentially, the application is running as a user which does not have access to any other drives. Therefore, it cannot find any file on any network drive. We will have to create an additional identity with the proper rights and set our applicationPool identity to use that custom account.
I found instructions on how to set this identity account here: http://technet.microsoft.com/en-us/library/cc771170%28v=ws.10%29.aspx
Assume I have a file that contains :
<%
Response.write("<my_tag>value</my_tag>")
%>
If I get it as an ordinary XML file, I get an error telling me that the XML have not the right format because it begin by "<%". How can I read this XML dynamically generated ?
Edit:
In fact, it was an illusion. The Server.Execute method just print the other file. What can I do ? How could I put the result of an ASP page in a string that I could read by loadXML method ? Or how could I just process the file before loading it ?
Give it a file extension that ASP will know to process, or tell ASP to process the file extension you're using. The server has to know to process the file and give you the dynamic result. It doesn't treat every file served as a classic ASP file, you have to tell it what to treat the file as if you're using a non-standard extension for ASP. You can do this by mapping the classic ASP handler to the file type you're trying to HTTP GET.
Use an .asp extension and set the Content Type:
<%
Response.CharSet = "utf-8"
Response.Buffer = True
Response.ContentType="text/xml"
Response.Write "<?xml version=""1.0"" encoding=""utf-8""?>"
Response.Write "<my_tag>value</my_tag>"
Response.Flush
%>
You might take a look here: http://www.w3.org/TR/REC-xml/
I'm new to ASP and having a little trouble.
A CMS is pushing out data into .txt files. I do not have the option to change what the CMS outputs, so they have to be .txt files.
a text file named textfile.txt looks like this:
widetxt=<P align='left'><B>Hello world!</B></P>&done=1
I need to display the "widetxt" variable on an .asp page.
The directory structure is like this:
ASP file is at the root of a folder, textfile.txt is located in a folder named "txt" off of the root folder.
index.asp
[txt]
|----textfile.txt
I tried the below code in the asp file, but I get a 500 error: "500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed."
<%
Set fs = CreateObject("Scripting.FileSystemObject")
Set wfile = fs.OpenTextFile(Server.MapPath("txt/textfile.txt"),1,true))
filecontent = wfile.ReadAll
wfile.close
Set wfile=nothing
Set fs=nothing
response.write(filecontent)
%>
I know for a fact both files are on the server and are where they are supposed to be.
If i remove the above code, and just put:
<%
response.write("Hello World!")
%>
the asp file works. So something in the OpenTextFile code is wrong, but i do not have the experience to know what it is.
Any help would be appreciated.
Set wfile = fs.OpenTextFile(Server.MapPath("txt/textfile.txt"),1,true))
You have one too many ) at the end of this statement. Every ( should have a matching ).
Set wfile = fs.OpenTextFile(Server.MapPath("txt/AttachmentFix.txt"),1,true)
Also, I don't see the remainder of your code, but after your response.write(filecontent) make sure to set filecontent as Nothing.
Set filecontent = Nothing
Also, when you're developing in Classic ASP #jsobo is right - you should have Friendly Error messages disabled as you can see what errors the script is throwing back.