Thanks for responding . . . Astro...I have code similar to yours that works just fine on my local machine. The real problem I'm having is that when I copy my code out to the web server and run the same code I get a file not found error when it tries to execute this line of code:
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); This is happening because the filePath is the local machine's path i.e. something like: C:\Stuff.doc . . . and the code is now executing on the web server so it's looking on the web server instead. How can I get around this??? I suppose I could store the file temporarily on the web server but I really don't want to do this . . . On Feb 7, 8:20 am, AstroDrabb <[email protected]> wrote: > On Fri, Feb 6, 2009 at 8:52 PM, Pete <[email protected]> wrote: > > > Hi, > > > I am relatively new to ASP.NET and I'm having a little trouble > > understanding how to accomplish something. In my ASP.NET Website on > > one of the Webforms I have a File Upload Control which allows the user > > to upload a file (either .pdf or .doc file) to a Web Server. I want to > > store the byte array of the file in an SQL Server Database. When I > > upload the file from the local hard drive (say C:\Stuff.doc) to the > > web server I lose the path to the file because it's relative to the > > web server. I need the original filename or it's equivalent to create > > the filestream in the code-behind on the web server. Can someone tell > > me how to do this or what I need to do here? Your help is much > > appreciated. > > > Thanks so much, > > > Pete > > //Just an example to insert > byte[] doc = GetFile(_filePath); > SqlConnection nwindConn = new SqlConnection("Data > Source=localhost;Integrated Security=SSPI;Initial > Catalog=Northwind;"); > SqlCommand cmd = new SqlCommand("INSERT INTO FileStore ([File]) " > + "Values(@File)", nwindConn); > cmd.Parameters.Add("@File", SqlDbType.Image, doc.Length).Value = doc; > > nwindConn.Open(); > cmd.ExecuteNonQuery(); > nwindConn.Close(); > > public static byte[] GetFile(string filePath) > { > FileStream fs = new FileStream(filePath, FileMode.Open, > FileAccess.Read); > BinaryReader br = new BinaryReader(fs); > > byte[] file = br.ReadBytes((int)fs.Length); > > br.Close(); > fs.Close(); > > return file; > > > > }- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text -
