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

asp.net , db Antarctica
  • 12 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 textbox_string = TextBox1.Text.ToString();
            //string replace_string = textbox_string.Replace('+', ' ');
            //String newfilepath = filepath.Replace("%20", " ");
            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 

Post a reply

No one has replied yet! Why not be the first?

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.

“Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.”