Friday, March 16, 2012

make a text file

this is mye code:

Dim fs, ffs = Server.CreateObject("Scripting.FileSystemObject")f = fs.OpenTextFile(Server.MapPath("userspass\" & TextBox1.Text & ".txt")) ', 8, False)f.WriteLine(TextBox2.Text)f.Close()f = Nothingfs = Nothing

and i need some help here.

1. it shold not make an text file of it eksist

2. put the file in a mapp named userspass

can sombody help me ?

Scripting.FileSystemObject is obsolete.

Public Sub makeFile()Dim fileStreamAs System.IO.FileStreamDim writerAs System.IO.StreamWriterDim filePathAs String = System.IO.Path.Combine(Server.MapPath("/userspass/"), TextBox1.Text &".txt")If Not System.IO.File.Exists(filePath)Then Try fileStream = System.IO.File.Open(filePath, IO.FileMode.CreateNew, IO.FileAccess.Write)'IO.FileMode.CreateNew causes error to throw if file exists writer =New System.IO.StreamWriter(fileStream) writer.WriteLine(TextBox2.Text)Finally If Not writerIs Nothing Then writer.Close()If Not fileStreamIs Nothing Then fileStream.Close()End Try End If End Sub

Make sure you give you aspnet account write permissions to the folder where you are creating the files.

Note: Not sure what your doing, but, if this is how you are storing user passwords...are you sure you really want to do this?


tnx tnx it worked and yes this is for storing passwords and i know that is no god idea but tnx

at a minimum, you should switch the .txt file extension to a .resources extension.

files with a .resources extension will not be served so it offers a small level of protection.


but one more thing how do i put inn this

if file eksist then

brukerlabel.text = "the user eksist"


like this:

If Not System.IO.File.Exists(filePath)Then'new user - create fileElse brukerlabel.text ="the user eksist"End If

yes but were to put ti in the code:

Dim fileStreamAs System.IO.FileStreamDim writerAs System.IO.StreamWriterDim filePathAsString = System.IO.Path.Combine(Server.MapPath("userpass/"), TextBox1.Text &".txt")IfNot System.IO.File.Exists(filePath)ThenTry

fileStream = System.IO.File.Open(filePath, IO.FileMode.CreateNew, IO.FileAccess.Write)

'IO.FileMode.CreateNew causes error to throw if file exists

writer =

New System.IO.StreamWriter(fileStream)

writer.WriteLine(

"ingen")FinallyIfNot writerIsNothingThen writer.Close()IfNot fileStreamIsNothingThen fileStream.Close()EndTryEndIfEndIf


like this:

Dim fileStreamAs System.IO.FileStreamDim writerAs System.IO.StreamWriterDim filePathAs String = System.IO.Path.Combine(Server.MapPath("userpass/"), TextBox1.Text &".txt")If Not System.IO.File.Exists(filePath)Then Try fileStream = System.IO.File.Open(filePath, IO.FileMode.CreateNew, IO.FileAccess.Write)'IO.FileMode.CreateNew causes error to throw if file exists writer =New System.IO.StreamWriter(fileStream) writer.WriteLine("ingen")Finally If Not writerIs Nothing Then writer.Close()If Not fileStreamIs Nothing Then fileStream.Close()End Try Else'file already existed brukerlabel.text ="the user eksist"End If

tnx works great
is it posibule to delite a txt file to ?

sure - just make sure that the aspnet account has proper ntfs permissions.

System.IO.File.Delete(filePath)

0 comments:

Post a Comment