Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can't create a file in wwwroot folder dynamically

Posted on 2002-06-23
8
Medium Priority
?
349 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
Industry Leaders: 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!

 
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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

721 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