Solved

Can't create a file in wwwroot folder dynamically

Posted on 2002-06-23
8
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 informatio…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

632 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