ASP read file
I am in need of finding a way to read a file on the clients computer, in order to see what version of some software he have installed.
What I need to find is the content of a file placed at c:\sow\version.txt, and find if there is a file at that location, and if so what the content is (which number ie 2.1 etc).
I sure hope that someone can help me with this, since it is rather crusual.
Thank you very mucb in advance.
~Casper Bang
secretsofwar.net
PS: I know this is in another thread as well, but I asked a mod to delete it... it was in the wrong forum. Sorry.
Peter J. Boettcher posted this at 14:18 — 4th June 2001.
They have: 812 posts
Joined: Feb 2000
You're not going to be able to do this with ASP unless the user uploads that file to your server. The alternative is to use a client-side control (ActiveX/Java) that gives you access to the client's file system.
PJ | Are we there yet?
pjboettcher.com
hotcut posted this at 16:34 — 4th June 2001.
They have: 133 posts
Joined: Sep 2000
hmm... do you have any idea on how to do that then?
I wouldn't mind if it were a javascript that finds the contents of the file, and posts it on... as long as I somehow get the content to the server... I don't know how hard it would be to write some kind of costum DLL that would allow the ASP to do so... Maybe you can guide me on the way!?
Thanks in advance
~casper
Peter J. Boettcher posted this at 17:21 — 4th June 2001.
They have: 812 posts
Joined: Feb 2000
You're not going to be able to do it with JavaScript since JS can't see the client's file system (for security reasons). I'll list the ways you can get the contents of that file, from easiest to hardest:
1) Make an upload form that the client uses to select that text file from their computer and uploads it to your server. On the server you can use a 3rd party tool like ASPUpload or create your own component to accept file uploads. Once the file is on the server you can analyze it's contents and do whatever processing you want.
2) Make an ActiveX control that scans the users file system for that text file, then sends the contents of it to a database.
3) Make an ActiveX control that scans the users file system for that text file, then send the contents of it to an ASP page for processing.
I would go with number 1, while it relies on the client to select the right file (can double check on client/server anyways) it still makes the most sense. Solutions 2 & 3 rely on the user installing an ActiveX control, a lot of big companies don't even allow ActiveX controls on their employees computers.
I think there are some freeware upload components at aspin.com
PJ | Are we there yet?
pjboettcher.com
hotcut posted this at 17:25 — 4th June 2001.
They have: 133 posts
Joined: Sep 2000
yea, ASPUpload (Persits.Upload) is installed on the server... So you think the easyest will be to somehow upload that file, scan it, save the information, and then delete it is the easyest? I suppose you are right... I will have to look at it, but I suppose I am able to do so. Thanks.
Thanks a lot for your help.
¨Caspoer
Peter J. Boettcher posted this at 17:56 — 4th June 2001.
They have: 812 posts
Joined: Feb 2000
If you have ASPUpload already then you should use it! Just upload to a temp directory, read the file using fso & textstream and save the results.
PJ | Are we there yet?
pjboettcher.com
hotcut posted this at 11:14 — 10th June 2001.
They have: 133 posts
Joined: Sep 2000
I have to confess, that I give up on this. I need more help.
I believe that I have found out how to upload a file that the user have posted, but that aint enough unfortunetly...
Where the file should be uploaded from shouldn't be told by the user, but from a database where I collect it! I haven't found a way to upload like that... can you help me with that?
When I have the file up, I guess that I can just use the filesystemobject to read the lines in the file, right?
I hope you can help me here.
~Casper
Peter J. Boettcher posted this at 13:10 — 11th June 2001.
They have: 812 posts
Joined: Feb 2000
You give up to easily!
Here's some code you can use as an example. Remember, the directory where you upload the file has to have write access.
Set Upload = Server.CreateObject("Persits.Upload.1")
'Limit file size to half meg
Upload.SetMaxSize 1048576
Upload.Save "d:\uploads"
For Each File In Upload.Files
GetFileName = (File.ExtractFileName)
Next
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
objFile = FileSystemObject.OpenTextFile("d:\uploads\" & GetFileName)
objTextStream = objFile.OpenAsTextStream
Do While objTextStream.AtEndOfStream <> True
strFileLine = objTextStream.Readline
strFileContent = strFileContent & strFileLine
Loop
objTextStream.Close
Set FileSystemObject = Nothing
If strFileContent <> "" Then
Set oCon = Server.CreateObject("ADODB.Connection")
Set oCmd = Server.CreateObject("ADODB.Command")
oCon.Open "Database"
With oCmd
.ActiveConnection = oCon
.CommandText = "StoredProcName"
.CommandType = adCmdStoredProc
.Parameters.Append oCmd.CreateParameter("SPText",adVarChar,adParamInput,1000,strFileContent)
End With
Set oCon = oCmd.Execute
Set oCmd = Nothing
oCon.Close
Set oCon = Nothing
Else
'Text File was empty
End If
This code was written the reply text box, so there's probably errors, but at least it gives you a starting point.
PJ | Are we there yet?
pjboettcher.com
hotcut posted this at 14:20 — 11th June 2001.
They have: 133 posts
Joined: Sep 2000
hi, and thanks...
the example gives me some knowledge about how to read the file when its uploaded, but that problem persist.
As far as I can tell, the user have to specify which file we are going to upload. It shouldn't be like that. The user have one time told me where the file is placed, and I just draw that out from the database. Like
Set Upload = Server.CreateObject("Persits.Upload.1")
Upload.SetMaxSize 1048576
Upload.source = "c:\1\version.txt"
Upload.Save "d:\uploads"
or something like that, so that I am in controll of the uploading... not the user.
I don't know if ASP are able to just grab a file from the client without the client asking for it - but I sure do hope so.
Do you know how I can do that?
btw, this part of your example
If strFileContent <> "" Then
Set oCon = Server.CreateObject("ADODB.Connection")
Set oCmd = Server.CreateObject("ADODB.Command")
oCon.Open "Database"
With oCmd
.ActiveConnection = oCon
.CommandText = "StoredProcName"
.CommandType = adCmdStoredProc
.Parameters.Append oCmd.CreateParameter("SPText",adVarChar,adParamInput,1000,strFileContent)
End With
Set oCon = oCmd.Execute
Set oCmd = Nothing
oCon.Close
Set oCon = Nothing
Else
'Text File was empty
End If
what does that do? Is it just to show me that it is here I work with the content of the file?
If we get the uploading to work, whats the fastest command for deleting the file after use (if its hard to do I will just leave it till next time, and let the script overwrite it).
Thank you very much for the help so far.
~Casper
Peter J. Boettcher posted this at 14:32 — 11th June 2001.
They have: 812 posts
Joined: Feb 2000
Well, we're back to the original problem. There is no way you can automate the file upload part on the client without some sort of ActiveX control. This is starting to sound like an application that would be better served as a client application (VB or C++). They would click some icon, and the program would go ahead and do all this stuff (read file, upload it to database).
That part of the code that you were wondering about is just the ADO code to run the stored procedure.
As for deleting the file, I forgot that part! You would just use the DeleteFile method of the FSO (object.DeleteFile(file))
PJ | Are we there yet?
pjboettcher.com
hotcut posted this at 14:36 — 11th June 2001.
They have: 133 posts
Joined: Sep 2000
hmmm... so you are saying that it is like imposible for a guy like me to do that? drats... I will have to live with it though
Anyway, thanks for your help
~Casper Bang
secretsofwar.net
Peter J. Boettcher posted this at 14:46 — 11th June 2001.
They have: 812 posts
Joined: Feb 2000
Nothing is impossible!
If you're comfortable programming in VBScript on your ASP pages then programming in VB shouldn't be a problem. You can even use the same object (FileScriptingObject) to find and read the text file. The only difference is, because your VB app runs on the client, it has access to all local and network drives.
PJ | Are we there yet?
pjboettcher.com
hotcut posted this at 14:51 — 11th June 2001.
They have: 133 posts
Joined: Sep 2000
hmm... yea just one problem; I know a lot of ASP, but I have never tried using VBscript running at a client... I would like to learn it some day... maybe you know a website with a toturial and stuff?
I might be able to fix a program that can scan the drives, and send it to the server etc... that would be cool!
Would I be able to make my server side applications ask the VBscript to run that code? It would be good if the client wouldn't have to open a program each time...
I will have to scan that file every time the visitors logs in, since I need to know if they have some software installed, or if it all should be run from the server... thats what I need it for...
Thanks
~Casper.
PS: How do you know so much?
Peter J. Boettcher posted this at 15:13 — 11th June 2001.
They have: 812 posts
Joined: Feb 2000
Check out abstractvb.com the code and learning sections are good.
You would not really be able to call this code from your server app, unless it was invoked in the browser. (It's possible, but a lot of coding is involved, an example of this is Windows Critical Update notification)
It's to bad that the software program can't write to a cookie file instead of a text file. That way you could read the cookie from your asp page. The only problem with that is if someone deletes their cookies.
P.S. I don't know that much!
PJ | Are we there yet?
pjboettcher.com
hotcut posted this at 15:31 — 11th June 2001.
They have: 133 posts
Joined: Sep 2000
hi,
Thanks once again.
I would like to put it in a cookie, but that aint enough unfortunetly...
The problem is that the user downloads some sounds, images and a lot of other things, which I need to know if he has on his computer, and if it is the right version. Therefore I need to check the directory where the files are in, to see if the version.html contains the latest verion-information; if the user has the current files.
Thats why I would need to run this all on the fly without the user knowing.
I will see what I can do, if you give me a working URL for that site It tells that the site doesn't work when I click it.
Thanks
~casper
PS: yea you know a lot
cds posted this at 21:56 — 28th June 2001.
They have: 359 posts
Joined: Mar 1999
Not sure if you are still looking for info on this subject, but company I work for does a full system inventory of all their computers worldwide on a weekly basis. It is done via the login script (NT) calling a batch file which runs a program called netcensus or at least it used to and then dumping the obtained info into a database.
This might be what you are looking for:
http://www.tallysys.com/
To see a sample report that I just had done on my own computer with their webcensus version, check this one out:
http://101usedvideogames.com/webcensus.html
Dan
Recycle Video Games Network
Stupidity killed the cat, curiosity was framed!
hotcut posted this at 12:15 — 7th July 2001.
They have: 133 posts
Joined: Sep 2000
Ok, As I weren't able to upload the files as I wanted, I was though able to use some of all this...
Now the problem is very simple.
I just need to make a file the content of what is posted by a form!
That should be simple!
But it wont work
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
objFile = FileSystemObject.OpenTextFile(server.mappath("breesy.txt"))
objTextStream = objFile.OpenAsTextStream
objTextStream.writeline = request.form("html")
objTextStream.Close
Set FileSystemObject = Nothing
it is ages ago since I used files to do anything... I once created a questbook this way, but changed it to a database...
There will only be one single line, which should be the content of the form posted.
However, when I try it, the following error come:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method
/breesy_forumbanner.asp, line 3
can someone help me?
Sorry fopr bothering you.
~Casper
Peter J. Boettcher posted this at 15:10 — 7th July 2001.
They have: 812 posts
Joined: Feb 2000
If you're just doing a bulk write (not line by line) then you don't need to use the textstream method. Try this:
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
objFile = FileSystemObject.OpenTextFile(server.mappath("breesy.txt"), 2, True)
objFile.Write = request.form("html")
objFile.Close
Set FileSystemObject = Nothing
Make sure the breesy.txt file exists and that it has write permissions.
PJ | Are we there yet?
pjboettcher.com
hotcut posted this at 15:34 — 7th July 2001.
They have: 133 posts
Joined: Sep 2000
hmmmm... seems simple, and I wish it was...
Unfortunetly I am getting the same reason as before:
The object doesn't support this method: 'objFile'
I have not idea what that means...
It clears the file perfectly, but that is all! It doesn't write ANYTHING in that file!
Can you help?
Thanks
~casper
Abhishek Reddy posted this at 01:04 — 9th July 2001.
He has: 3,348 posts
Joined: Jul 2001
hi hotcut,
i hope it helped
hotcut posted this at 10:26 — 17th July 2001.
They have: 133 posts
Joined: Sep 2000
I finally found the error!
Peter, you said I should use
fso.write = "..."
But I should have used
fso.write "..."
Now it works perfectly!
Thank you all very much!
Abhishek , You were also right that I needed to stop using filesystemobject as a variable. That screwed it up as well.
You said that I should dim my variables... Can you explain me why? I never do that... Don't know the difference (I only do it when I use arrays).
Thanks
Vasper
Abhishek Reddy posted this at 10:42 — 17th July 2001.
He has: 3,348 posts
Joined: Jul 2001
hi again,
im not sure, but i think that previous versions of asp required you to dim all variables.
as far as dimming goes, it is really really good programming habit. i know it sounds like extra unnecessary work, but its a good idea to do it.
it tells you about the variables in the following code and even what type they are. eg: dimming a variable as an integer tells you that it is an integer. it helps you read and understand code better.
imagine if you posted some code on the forums or someone else reads your code, it would be hard for them to understand exactly what does what.. if you dimmed the vars, it makes it more readable to someone whos not particularly familiar with that piece of code.
it also helps you debug and keep track of vars in code that can sometime span 100's of lines.
and thats that.
Mark Hensler posted this at 17:09 — 17th July 2001.
He has: 4,048 posts
Joined: Aug 2000
If you use Option Explicit (at the top of the code), then you'll only be able to use dimmed variables. If you try to use a variable that was not dimmed, the program/script will error out. This helps prevent mispelling of variables.
Mark Hensler
If there is no answer on Google, then there is no question.
hotcut posted this at 17:28 — 17th July 2001.
They have: 133 posts
Joined: Sep 2000
Yea, that I know...
I used to define all my variables, but it just kept happen that I degined them twice, and not even the "on error resume next" would take care of that for me!
I got annoyed, and stopped dimming them.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.