Create Virtual Directory IIS7 to be use in GetFolder in Server.CreateObject("Scripting.FileSystemObject") - asp-classic

I am trying to create a virtual directory at my IIS7 and then use the virtual directory in the following code
sPath = "\CMapped\database\attendanceData\"
sDir = Server.MapPath(".") & sPath
response.write sDir
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set obj_FolderBase = fso.GetFolder(sDir)
response.end
But I got the following error:
What I have done is as follow:
I created the virtual directory and set the path to C:\ Drive. My localhost is at D:\ drive. I have also set Connect as and entered my log in and password. I am the administrator of the PC. Everything authorized.
Then I go to C: and set it as a shared folder
I went back to IIS and click on the virtual directory -> Managed Virtual Directory -> Browse. I successfully connect to the directory
Now when I try the code, everything failed. The GetFolder function doesn't seems to recognize the path. The web server is at D: and the file server is at C: Please help.
sPath = "\CMapped\database\attendanceData\"
sDir = Server.MapPath(".") & sPath
response.write sDir
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set obj_FolderBase = fso.GetFolder(sDir)
response.end
The directory structure

What you are trying would work in an href or src attribute, or with
<!--#include virtual="\CMapped\database\attendanceData\yourfile.asp"-->.
With server.mappath though I think you need to use the physical directory structure on the machine. As your virtual directory is on a different drive I suggest you go with
sDir = "C:\full_physical_path_to\database\attendanceData\"

Related

Unable to save Selected File to directory when not on the development server

When I am on the development server testing, the following code will save the document in the directory I want it to be in... But when I test it on another computer from the network, the file will not save to the directory. The Directory has "Everyone" Full access but still has this problem.
Protected Sub btnSCSoldSheets_Click(sender As Object, e As EventArgs) Handles btnSCSoldSheets.Click
If fuSCSold.FileName = Nothing Then
Exit Sub
Else
Dim fileName As String = Path.GetFileName(fuSCSold.PostedFile.FileName)
fuSCSold.PostedFile.SaveAs(Server.MapPath("~/ISI/ScoreCard/ScoreCardFiles/") + fileName)
lblFileNameSCSold.Text = fileName
generateExcelSheets()
End If
End Sub
I figured it out... So silly on my part.
When I copied the website from development to production, I didn't change the physical directory to match what was in production.

System.UnauthorizedAccessException: Access to path is denied

Good afternoon,
I have recently purchased a server with Plesk 12 as the Control Panel.
I don't have much experience using Plesk.
For testing purposes, I created a simple ASP.NET project which tries to read/write from a txt, as shown below:
String logPath = #"C:\inetpub\vhosts\xxx.com\httpdocs\log_application_error.txt";
StreamWriter textWriter = new StreamWriter(logPath, true);
When the StreamWriter instance is created, I get the following error:
System.UnauthorizedAccessException: Access to the path 'C:\inetpub\vhosts\xxx.com\httpdocs\log_application_error.txt' is denied.
I tried granting read/write permissions to the txt file, and even granted Full Control to "Everyone", but the result was the same.
Plesk seems to hide everything so that it is handled through the Control Panel. I don't see any Applications Pools on the IIS so I am not even sure what is the identity it is running under.
Any help would be greatly appreciated.
Try to set "Additonal write/modify permissions" at "Hosting settings" of your domain:
Try to fix it with following commands:
cacls C:\Windows\assembly\GAC_MSIL /E /R psacln /T /C
cacls C:\Windows\assembly\GAC_MSIL /E /R psaadm /T /C

Save file outside the root directory vb.net

Hi I am developing web application in vb.net. I was facing problem while uploading my file from client side to the server side folder using this code
Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim ext As String = System.IO.Path.GetExtension(fileName)
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/EmployeeSignature/../../") + "IMG12345" & ext)
Here is root and target folders structure
Here is my site internal structure (UploadingTest)
Problem is that at this line
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/EmployeeSignature/../../") + "IMG12345" & ext)
I am getting error message
Cannot use a leading .. to exit above the top directory.
My requirement is to save file above the root directory , try alot but unable to solve problem , Kindly suggest any solution! Thanks
In IIS, Add Virtual Directories inside you Website
EmployeeSignature
Images
Now you can access the folders using below code
HttpContext.Current.Server.MapPath("EmployeeSignatures")
HttpContext.Current.Server.MapPath("Images")
You can't use .. in the logical path to step outside the folder of your web root when you use MapPath to convert it. Move those outside the MapPath call:
Server.MapPath("~") + "\..\EmployeeSignature\IMG12345" + ext

cannot find file when accessing via virtual directory in classic asp

i am accessing files in a virtual folder using classic asp by server objects. here is the code for getting the folder:
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Dim mapPath
mapPath = Server.MapPath("http://development/far/")
Set farFolder = FSO.GetFolder(mapPath)
I am getting file not found error when looping through the directory. The files are seen when i put //development/far/ in the browser. I am fairly new to asp so do not know where going wrong.
this is code for when looping through the directory:
For Each item in farFolder.Files
Set matches = re.Execute(item.Name)
if(matches.Count=1) then
Response.Write ("<a target=""_blank""href=""" & item.Path & """>" & item.Name & "</a> <br>")
End if
Next
Just use the path part of your URL when calling Server.MapPath():
mapPath = Server.MapPath("/far/")

How to delete file from directory using vb.net?

I have a asp.net website folder namely Website3 inside website3 folder there is a upload folder. I want to delete files inside upload folder on button click event.
MY directory status :
Website3 > upload
I'm using the following command but it doesn't delete the file from upload directory
Protected Sub ListView1_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewDeletedEventArgs) Handles ListView1.ItemDeleted
Dim lab As Label = CType(ListView1.Items(ListView1.SelectedValue).FindControl("photoLabel"), Label)
System.IO.File.Delete(System.IO.Path.GetDirectoryName("/upload/") & lab.Text)
End Sub
You should be using Server.MapPath
File.Delete((MapPath(".") + ("\\" + lab.Text)))
Just try this:
Public Function DelAllUploadedFiles()
For Each Uploadedfiles As var In System.IO.Directory.GetFiles(Server.MapPath("~/upload/"))
System.IO.File.Delete(Uploadedfiles )
Next
End Function
Try to put try and catch and see if you have
Exception . In general in order to delete in IIS process pool ,should be defined under strong user .
First you have to set the folder settings on the server
who can enter this folder and has delete authority
Login to your server account and give delete permission to the folder to everyone

Resources