Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

server.map

Status
Not open for further replies.

valed74

Technical User
Dec 14, 2004
5
IT
hi, i'm valerio from Italy.
I know a bit of vbscript as i know a bit of english...
so, sorry for both type of error that I will do!!

Can anyone help me?
I would like to write the following script so that it cuold run trought the server but I don't know exatly where I have to write server.mappath
.......
origine = "C:\dati\" & pre & "\" & mille & cento & zero & Conta & ".html"

Set fso =CreateObject("Scripting.FileSystemObject")

if not fso.FileExists (origine)........


hello, Valerio
 
Hello valed74,

If you hard code the absolute path as seen by the server, I don't think you need server.mappath to get to it. Are you getting problem doing what you've shown us? (For server-side code, may be [blue]server.[/blue]createobject() might help you more.

regards - tsuji
 
I made the tests on my computer but I haven't tested the script on the server yet. I only red thet when creating or opening a document on the server the path is clearly different. I found a lot of example with asp that show how to write the relative path using mapPath but I didn't find how to write it in vbscript. you're perfecly right, I have to make the tests before!!!
In italy we say: "don't bind youre head before falling".

In the meanwhile it seams that I have another problem to solve: I'have done a form to creating files.txt that contain the information inserted by the client in the form. It works, but when there are more than one i.e. windows opened there is an error regarding Scripting.FileSystemObject and its impossibility in creating Object. Any Idea on how I could solve this?

thank you
regards, Valerio
 
valed74,

I'm afraid you've got to show the forum what you have and where it's stuck rather than us imagining...

- tsuji
 
this is the code. When pushing the submit button appears a message that says that the interaction of one control activex is potentially harmful. If I say yes sometimes the script works end it writes the file.html on my harddisc, but sometims the the script dosen't work and appears an error that says : activex can not create the object "Scripting.FileSystemObject"

valerio

<HTML>

<HEAD>

<TITLE>ISCRIZIONE</TITLE>


<SCRIPT LANGUAGE="VBScript">

<!-- Instruct non-IE browsers to skip over VBScript modules.

Option Explicit
DIM contenuto
dim fso
Dim OggFile, origine, OggTextStream
Dim Conta
dim nome
DIM cognome
dim telefono
dim indirizzo
dim cellulare
dim pre
dim zero
dim cento
dim mille
dim data







Sub cmdSubmit_OnClick

data = Now
contenuto=document.frmExample5a.txtAge.value
nome=document.frmExample5a.nom.value
cognome=document.frmExample5a.cognom.value
telefono=document.frmExample5a.telefon.value
indirizzo=document.frmExample5a.indirizz.value
cellulare=document.frmExample5a.cellular.value
pre=document.frmExample5a.pr.value

'MsgBox contenuto

document.frmExample5a.submit



Conta=1
zero=0
cento=0
mille=0


do While Conta > 0

if conta > 9 then
zero=""
end if

if conta > 99 then
zero=""
cento=""
end if
if conta > 999 then
zero=""
cento=""
mille=""
end if


'HERE IS THE PROBLEM
origine="c:\dati\" & pre & "\" & mille & cento & zero & Conta & ".html"
Set fso = CreateObject("Scripting.FileSystemObject")

if not fso.FileExists (origine) then

fso.CreateTextFile (origine)
Set OggFile = fso.GetFile (origine)
Set OggTextStream = OggFile.OpenAsTextStream(2)
'OggTextStream.WriteLine "nome : " & nome
'OggTextStream.WriteLine "cognome : " & cognome
'OggTextStream.WriteLine "telefono : " & telefono
'OggTextStream.WriteLine "indirizzo : " & indirizzo
'OggTextStream.WriteLine "cellulare : " & cellulare
'OggTextStream.WriteLine "preiscrizione: " & pre
'OggTextStream.WriteLine "eta : " & contenuto
'OggTextStream.WriteLine "data : " & data



OggTextStream.WriteLine "<html><head><title></title></head><body><table border=1><tr><td>nome</td><td>" & nome & "</td></tr>"
OggTextStream.WriteLine "<tr><td>cognome</td><td>" & cognome & " </td></tr>"
OggTextStream.WriteLine "<tr><td>telefono</td><td>" & telefono & "</td></tr>"
OggTextStream.WriteLine "<tr><td>indirizzo</td><td>" & indirizzo & "</td></tr>"
OggTextStream.WriteLine "<tr><td>cellulare</td><td>" & cellulare & "</td></tr>"
OggTextStream.WriteLine "<tr><td>preiscrizione</td><td>" & pre & "</td></tr>"
OggTextStream.WriteLine "<tr><td>eta</td><td>" & contenuto & "</td></tr>"
OggTextStream.WriteLine "<tr><td>data</td><td>" & data & "</td></tr></table></body></html>"


contenuto=""
nome=""
cognome=""
telefono=""
indirizzo=""
cellulare=""
pre=""

document.frmExample5a.txtAge.value=""
document.frmExample5a.nom.value=""
document.frmExample5a.cognom.value=""
document.frmExample5a.telefon.value=""
document.frmExample5a.indirizz.value=""
document.frmExample5a.cellular.value=""
document.frmExample5a.pr.value=""

OggTextStream.close
msgbox "executed writing. Youre number is " & mille & cento & zero & Conta

'document.write "executed writing. Youre number is " & mille & cento & zero & Conta


'if conta=30 then
exit sub
'end if
Else

Conta=Conta+1
End if
loop

End Sub

-->

</SCRIPT>
<STYLE>
.HEADING { FONT-SIZE: 12px; COLOR: #000033; FONT-FAMILY: Tahoma }
</STYLE>

</HEAD>

<BODY>
<H1>A VBScript Example on Variables</H1>

<P> This example demonstrates validation techniques in VBScript. </P>

<FORM NAME="frmExample5a">


<table>
<tr>
<td class="HEADING">Nome:</td>
<td class="HEADING"><INPUT TYPE="Text" NAME="Nom" SIZE="40" class="HEADING"></td>
</tr>
<tr>
<td class="HEADING">Cognome:</td>
<td class="HEADING"><INPUT NAME="Cognom" TYPE="text" SIZE="40" class="HEADING"></td>
</tr>
<tr>
<td class="HEADING">Indirizzo:</td>
<td class="HEADING"><INPUT NAME="Indirizz" TYPE="text" SIZE="40" class="HEADING"></td>
</tr>
<tr>
<td class="HEADING">Telefono:</td>
<td class="HEADING"><INPUT NAME="Telefon" TYPE="text" SIZE="40" class="HEADING"></td>
</tr>
<tr>
<td class="HEADING">cell:</td>
<td class="HEADING"><INPUT NAME="cellular" TYPE="text" SIZE="40" class="HEADING"></td>
</tr>
<tr>
<td class="HEADING">inserisci idati in:</td>
<td class="HEADING">
<SELECT SIZE=1 NAME="pr">
<OPTION SELECTED>
<OPTION class="HEADING" VALUE=cartella1>cartella1
<OPTION class="HEADING" VALUE=cartella2>cartella2
<OPTION class="HEADING" VALUE=cartella3>cartella3
<OPTION class="HEADING" VALUE=cartella4>cartella4
</SELECT>
</td>
</tr>


<TR>

<TD class="HEADING">Enter your age:</TD>

<TD><INPUT TYPE="Text" NAME="txtAge" SIZE="2">

<TR>

<TD class="HEADING"><INPUT class="HEADING" TYPE="Button" NAME="cmdSubmit" VALUE="Submit"></TD>

<TD></TD>

</TR>


</TABLE>

</FORM>

</BODY>

</HTML>
 
valed74,

I have just got the time yet to roughly look at your script. Some observation till this moment.

[1] Yours script seems to be client-side. Some no question about server.mappath, it seems?

[2] Should you not validate "pre" rejecting if it is empty (="")?

[3] You can simply the device of Conta, zero,... etc by padding 0 in front using this:
[tt]
if conta<1000 then
origine="c:\dati\" & pre & "\" & right("0000" & cstr(conta),4) & ".html"
else
origine="c:\dati\" & pre & "\" & cstr(conta) & ".html"
end if
[/tt]
[4] You use createtextfile(origine). It is already a textstream object ready for writing. The twiste you construct it, you have to play safe by .close it and wait a while to proceed to getfile. Else, it might fail. Hence, I would revise it to.
[tt]
[red]set oggTextStream=[/red]fso.CreateTextFile (origine)
[red]oggTextStream.close[/red]
Set OggFile = fso.GetFile (origine)
Set OggTextStream = OggFile.OpenAsTextStream(2)
[/tt]
(I use oggTextStream up there to avoid new name, as you use option explicit.)
In fact, I would suggest use directly oggTextStream like this to replace the above block.
[tt]
set oggTextStream=fso.CreateTextFile(origine)
[/tt]
The rest are redundant and might cause timing trouble.

[5] I should verify this before saying here. Make sure your .submit statement does not have adverse effect on the rest of the sub. But, this can be easily checked for sanity.

This is I would suggest sofar.

- tsuji
 
Great!!! No more "activex can not create the object Scripting.FileSystemObject"
there is always the message that says that the interaction of the control activex is potentially harmful. but now it works always if I say yes.

"Pre" is a variable that takes the value of the congobox becose I intend to not seve any data in the folder colled data but only in in the folders that will be contained in it.

Is it realy different if I'd like to put the script on the server so that who visit the internet site could seve his data in one folder of the server?

Tank you, Valerio
 
valed74,

I would like to continue on your original script.

[6] Put you set fso line outside of the Conta loop, that is a bit better practice.

[2bis] I know pre is a data retrieve from a form, I only meant you should validate it in case that piece of data is empty or some unacceptable name for any folder.

If you put the part after the .submit on the server with variables retrieved from request.form() etc, major consideration is to the security issue. It is not unheard-of using fso on server and it is perfectly respectable, hence, it is doable.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top