Help Problem upload file into the database.....urgent?

asp.net , db Antarctica
  • 10 years ago

     Hi friends i m trying to upload file into the database but i got following error..plz help its urgent.




    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;
    using System.IO;
    using System.ComponentModel;
    using System.Drawing.Imaging;
    using System.Text;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //http://localhost/addressbook/Default.aspx?filepath1="samplevcffile.vcf";//when i excute it into the browser
           

           String filepath = Request.QueryString["filepath1"];
            Response.Write(filepath);
           
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("db2.mdb");//server.mappath("db2.mdb") + ";";
            OleDbConnection cn = new OleDbConnection(strConn);
            try
            {

                OleDbCommand cmd = new OleDbCommand("insert into text_table (vcffile) values(@)", cn);

                String str2 = "H:\\"+filepath;//Path.GetFileName(read);

                FileStream fs = new FileStream(str2, FileMode.Open, FileAccess.Read);

                Byte[] txtbyte = new Byte[fs.Length];

                fs.Read(txtbyte, 0, txtbyte.Length);

                fs.Close();

                OleDbParameter param = new OleDbParameter("@vcf", System.Data.OleDb.OleDbType.VarBinary, txtbyte.Length, ParameterDirection.Input, false,
                 0, 0, null, System.Data.DataRowVersion.Current, txtbyte);

                cmd.Parameters.Add(param);

                cn.Open();

                cmd.ExecuteNonQuery();

                Response.Write("Vcf File Successfully Uploaded into the Database");
            }
            catch (Exception Ex)
            {
                Response.Write(Ex.ToString());
            }
            finally
           {
            cn.Close();
           }
        }


    ERROR://System.ArgumentException: Illegal characters in path. at System.IO.Path.CheckInvalidPathChars(String path) at System.IO.Path.GetFileName(String path) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at _Default.Page_Load(Object sender, EventArgs e) in h:\AddressBook\Default.aspx.cs:line 47 

  • 10 years ago

    Hi,

    What is the filepath that you are putting in?  i see you are response writing it, can you let us know what that is?

    Regards

    Si

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson