Solved

Can't create a file in wwwroot folder dynamically

Posted on 2002-06-23
8
346 Views
Last Modified: 2007-12-19
Hello All,

I'm not able to create a file in my virtual folder using File System object. But i'm able to create the file outside wwwroot dir. The error i'm getting is object required. Please guide me in this regard.

Please check the following code:
-----------------------------------
FileData = "lskdjf laskjdfl askdfj lasdkfj l"
FileName = "test1.doc"

call SaveToDisk("c:\inetpub\") 'this works
call SaveToDisk("c:\inetpub\wwwroot\xyz") 'this doesn't work


Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
on error resume next
If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) > "\" Then sPath = sPath & "\"

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub
     
Set oFile = oFS.CreateTextFile(sPath & FileName, True)
         
     For nIndex = 1 to LenB(FileData)
         oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
     Next

Response.Write "
Error : " & err.Description
Response.Write "
Err No. : " & err.number
Response.Write "
Err source : " & err.Source

     oFile.Close
End Sub
-----------------------------------

Thankx in advance
Ayub
0
Comment
Question by:akayubm
  • 4
  • 3
8 Comments
 
LVL 30

Expert Comment

by:third
ID: 7103057
try,


Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex
on error resume next
If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) > "\" Then sPath = sPath & "\"

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub
   
Set oFile = oFS.CreateTextFile(Server.Mappath(sPath & FileName), True)
         
    For nIndex = 1 to LenB(FileData)
        oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
    Next

Response.Write "
Error : " & err.Description
Response.Write "
Err No. : " & err.number
Response.Write "
Err source : " & err.Source

    oFile.Close
End Sub
0
 

Author Comment

by:akayubm
ID: 7103094
When i use Server.MapPath even then i'm getting the same error, i.e Object required [VB Script runtime error] error no. 424.
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7103161
Which ASP version is available on your server?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 30

Expert Comment

by:third
ID: 7103173
when you use server.mappath you need to change your procedure call to,

SaveToDisk "xyz"

where "xyz" is a virtual path in your server.
0
 

Author Comment

by:akayubm
ID: 7103341
I'm using IIS 5.0 on Windows 2000 Advance Server.
With VBScript 5.1

And Mr. third.. can u give me an example as to how to enter a virtual path. Like i have a virtual directory called "cr" mapped to physical dir "cr" in the web server. I want to create the files in this folder. Then how do i give the path. Plz help.

Thankx in advance
Ayub
0
 
LVL 30

Accepted Solution

by:
third earned 250 total points
ID: 7106086
ok use this,

<%

FileData = "lskdjf laskjdfl askdfj lasdkfj l"
FileName = "test1.doc"

Sub setTxtFile(textfile, newtxt)
  Const fsoForWriting = 2

  Dim objFSO
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

  'Open the text file
  Dim objTextStream
  Set objTextStream = objFSO.OpenTextFile(textfile, fsoForWriting, True)

  'Write to the text file. Overwrite existing text
  objTextStream.Write newtxt
 
'  response.write "Save Succesful!"
 
  'Close the file and clean up
  objTextStream.Close
  Set objTextStream = Nothing
  Set objFSO = Nothing
End Sub

response.write Server.Mappath("cr\"&Filename)
setTxtFile Server.Mappath("cr\"&Filename), FileData
%>
0
 

Author Comment

by:akayubm
ID: 7106744
thanx Mr. third
0
 

Author Comment

by:akayubm
ID: 7106781
thanx Mr. third
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to hide hopscotch tour popup page reload? 2 96
Field that has HTML displays the code instead of the text in html 16 94
asp syntax 3 57
Hide cell in a table 2 27
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question