Creating text files in protected directory

Results 1 to 2 of 2

Thread: Creating text files in protected directory

  1. #1
    Join Date
    Dec 1969

    Default Creating text files in protected directory

    I am trying to check to see if a file exists in a protected directory. If it doesn&#039;t, create a new file and write to it. If it does exist, just open the existing file and write to it. The problem I am having is when I open the browser (IE 6) and run the code, I get the following error (the file exists when I am trying this):<BR><BR>Microsoft VBScript runtime error &#039;800a0046&#039; <BR>Permission denied <BR>/scripts/formscripts.asp, line 652 <BR><BR>If I open the file in the browser (I get an authentication dialog box and enter my user ID and password) and then go back and run the code, everything is fine (the file is detected) and the row is written out. If I close the browser and try it again, I get the same error. Is there something I need to do to authenticate to the server before trying to create the text file? Here is the code I&#039;m using. Thanks in advance.<BR><BR>Sub SaveCSVFile(theForm, bodyType, theFilename)<BR>&#039; Set up any needed variables <BR>Dim fsCSVFile &#039;FileSystem Object<BR>Dim fileCSVFile &#039;File Object<BR>Dim filePath &#039;Where the file will be physically located<BR>Dim ts &#039;TextStream Object<BR>Dim csvString &#039;Data to write to the file<BR>Const ForReading = 1<BR>Const ForWriting = 2<BR>Const ForAppending = 8<BR>Const UseDefaultFormat = -2<BR>Const UnicodeFormat = -1<BR>Const ASCIIFormat = 0<BR> <BR>&#039; Find the physical path to the file on the server.<BR>Response.Write "theFilename = " & theFilename<BR>filePath = Server.MapPath(theFilename)<BR>Response.Write "Filepath = " & filePath<BR>&#039; Create a FileSystem Object for the information. <BR>Set fsObj = Server.CreateObject("Scripting.FileSystemObject")< BR> <BR>&#039; Check to determine if the file exists. If it does not, create a new file and <BR>&#039; populate the first row with the field names.<BR>If fsObj.FileExists(filePath) Then<BR>Response.Write "File " & filePath & " exists!!"<BR>&#039; Open a File Object using an existing file.<BR>Set tsObj = fsObj.OpenTextFile(filePath, ForAppending, TRUE)<BR>Else<BR>Response.Write "File " & filePath & " does not exist!!"<BR>&#039; Create a File Object that does not over write a file if it exists and is in ASCII format.<BR>Set tsObj = fsObj.CreateTextFile(filePath, False, False) <BR>&#039; Build the file header.<BR>Response.Write "bodyType = " & bodyType<BR>csvHeader = BuildCSVFileHeader(bodyType)<BR>Response.Write "csvHeader = " & csvHeader<BR>tsObj.WriteLine csvHeader <BR>End If<BR><BR>&#039; Build the text string that is to be written to the file.<BR>csvBody = BuildCSVFileBody(theForm, bodyType)<BR> <BR>Response.Write "csvBody = " & csvBody<BR><BR>tsObj.WriteLine csvBody<BR><BR>&#039; Close the file.<BR>tsObj.Close<BR> <BR>&#039;Clean up resources.<BR>Set tsObj = Nothing<BR>Set fileObj = Nothing<BR>Set fsObj = Nothing<BR><BR>End Sub &#039;SaveCSVFile<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Creating text files in protected directory

    Well, if the IUSR_machinename account doesn&#039;t have access to the file, then you won&#039;t be able to access it from the asp page without authenticating. Of course, when you authenticated yourself then ran the page, it would work because you&#039;re authenticated for that browser session. But, like you said, as soon as you close that browser window, you&#039;re not authenticated anymore.<BR>There is a way to authenticate yourself through script, i&#039;m sure. I haven&#039;t had a need for it yet, so I can&#039;t tell you exactly how for sure. Do a search on Google for something like "authenticating through an ASP page" and I&#039;m sure you&#039;ll find something about impersonation. Like I said, I&#039;m not sure, but hopefully this will help. If not, then I don&#039;t know what the hell i&#039;m talking about and I&#039;ve just wasted 3 mins of your life MWAHAHAHA!<BR>~~Chaotix

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts