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
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