Reading a local file ASP/VB ,net 2005

A

AMP

I am trying to open a local text files on a client network, and store

the details in a database



Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
pvfilecount = pvfilecount + 1
Dim uploadedFiles As HttpFileCollection = Request.Files
Dim userPostedFile As HttpPostedFile = uploadedFiles(0)
Me.ListBox1.Items.Add(userPostedFile.FileName)
Dim fp As StreamReader
Dim fileContents As String = ""
'fileContents
Try
fp = File.OpenText(userPostedFile.FileName)
fileContents = fp.ReadToEnd()
Me.Label1.Text = fileContents
fp.Close()
Catch err As Exception
Me.Label1.Text = "File Read Failed. Reason is as follows "
& err.ToString()
Finally

End Try

'Dim fileContents As String
'fileContents =
My.Computer.FileSystem.ReadAllText(userPostedFile.FileName)
'Me.Label1.Text = fileContents
pvfilecontent = pvfilecontent + Chr(13) + pvfilecount.ToString
+ "---- " + getname(userPostedFile.FileName)
pvfilecontent = pvfilecontent + Chr(13) +
fileContents.ToString + Chr(13)
End Sub


the pvfilecontent is then stored in a database





I am using MS visual studios . net 2005 with VB/ASP





This works when testing on a dev server but if I run this as a WWW it

fails with

File Read Failed. Reason is as follows
System.IO.FileNotFoundException: Could not find file '\\server\share
\upload\SQLQuery2.sql'. File name: '\\server\share\upload
\SQLQuery2.sql' at System.IO.__Error.WinIOError(Int32 errorCode,
String maybeFullPath) at System.IO.FileStream.Init(String path,
FileMode mode, FileAccess access, Int32 rights, Boolean useRights,
FileShare share, Int32 bufferSize, FileOptions options,
SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options) at
System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean
detectEncodingFromByteOrderMarks, Int32 bufferSize) at
System.IO.StreamReader..ctor(String path) at
System.IO.File.OpenText(String path) at
Requestform.Button1_Click(Object sender, EventArgs e)

What am I doing wrong
 
C

Cor Ligthert[MVP]

Allan,

The error message is quiet clear in my idea, it could not find the file on
the place where you tells that it is stored on the server.

Cor
 
A

AMP

Allan,

The error message is quiet clear in my idea, it could not find the file on
the place where you tells that it is stored on the server.

Cor

"AMP" <[email protected]> schreef in bericht













- Show quoted text -

I am using a browse button to find the file so I know the file is
there and spelt correctly
.

The file is the same when using the Intranet or the internet version.
the intranet works OK, so why not the internet version?
 
C

Cor Ligthert [MVP]

You mean that you want to access a file on a client computer, forget it, it
is called hacking.
(Maybe you want to do it on computers from your own company, however all
security updates are to prevent that)

Cor
 
B

Bill McCarthy

Hi,

You can't use the path to read the stream, instead you use the InputStream,
eg: userPostedFile.InputStream and read from that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top