Click to See Complete Forum and Search --> : Handling content of .txt files


Calimero
11-11-2004, 03:11 PM
Hi ya all !

var Problem = "I would like JavaScript to open a .txt file on my computer and to take it's content into a variable for further work.";

var Question = " IS THIS POSSIBLE ? ";

var The_Post = Problem + Question;

document.write(The_Post);



// Ahhhhh, wish that all of my JS Problems were this simple :)


In code/snippet form if possible. :D

Thanks Ahead !

Vladdy
11-11-2004, 04:58 PM
if(forumSearch == "has not been done prior posting a question")
{ behaviour = "ignore the post";
return;
}


:rolleyes:

Charles
11-11-2004, 05:01 PM
If it were possible for every web site to play around with the contents of your hard drive would you surf the web?

Calimero
11-11-2004, 06:49 PM
For the first reply:

I did search, but because I don't have a clue with what keywords to search - I tried several times, but got no real solution in search results. If someone has keywords, please post-em, or even better post a link with a search - results.


For the second:

Honestly I don't know if it is possible, I used php and such actions are very easy to work on, but I'm still new to JS, so trying to get answers on the right place

senshi
11-11-2004, 07:20 PM
Might I suggest you lookie over here

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsmthopentextfile.asp

Something that you can do in javascript, you will have an active x pop up warning depending on your browsers settings.

Warren86
11-12-2004, 06:47 AM
<HTML>
<Head>
<Script language=VBScript>

fileSpec = "Test.txt"

Sub saveThis_OnClick
isData = xferContent.innerHTML
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(fileSpec) Then
MsgBox "Test.txt already exists...", vbInformation, "Information"
Exit Sub
End If
Set contentFile = fso.CreateTextFile(fileSpec,True)
contentFile.WriteLine(isData)
contentFile.Close
MsgBox "Successfully saved Test.txt to the Desktop", vbInformation, "Information"
set fso = Nothing
End Sub

Sub appendThis_OnClick
isData = appendContent.innerHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set contentFile = fso.GetFile(fileSpec)
Set fsoStream = contentFile.OpenAsTextStream(8)
fsoStream.WriteLine(isData)
fsoStream.Close
MsgBox "Successfully appended to Test.txt", vbInformation, "Information"
Set fsoStream = Nothing
Set fso = Nothing
End Sub

Sub readThis_onClick
Set fso = CreateObject("Scripting.FileSystemObject")
Set contentFile = fso.GetFile(fileSpec)
Set fsoStream = contentFile.OpenAsTextStream(1)
isData = fsoStream.ReadAll
readContent.innerHTML = isData
fsoStream.Close
Set fsoStream = Nothing
Set fso = Nothing
End Sub

Sub showInfo_onClick
Set fso = CreateObject("Scripting.FileSystemObject")
Set contentFile = fso.GetFile(fileSpec)
strInfo = contentFile.Name & vbCrLf
strInfo = strInfo & "Created: "
strInfo = strInfo & contentFile.DateCreated & vbCrLf
strInfo = strInfo & "Last Accessed: "
strInfo = strInfo & contentFile.DateLastAccessed & vbCrLf
strInfo = strInfo & "Last Modified: "
strInfo = strInfo & contentFile.DateLastModified
MsgBox strInfo, vbInformation, "File Information"
Set contentFile = Nothing
Set fso = Nothing
End Sub

</Script>
</Head>
<Body>
<center>
<Div id=xferContent> This is the text that will be saved. </Div>
<Div id=appendContent> And this is the text that will be appended to the file. </Div>
<br>
<input type=button value='Save to text file' Name='saveThis'>
<br><br>
<input type=button value='Append to the file' Name='appendThis'>
<br><br>
<input type=button value='Read from the file' Name='readThis'>
<br><br>
<input type=button value='Display File Info' Name='showInfo'>
<br><br>
<br><br>
</center>
<Div id=readContent Style='Font Size:16pt;Color:Blue;'></Div>
</Body>
</HTML>

baconbutty
11-12-2004, 09:00 AM
See also this thread

http://www.webdeveloper.com/forum/showthread.php?s=&threadid=44386