Hi,
I need some guidence or some tutorials which will teach me how to do ,
i am not sure is this the correct forum i am in.

i need a way to upload any kind of file from the fileUpload control to MySQL server how can i do this,
i searched in the internet and i got one with php but i am not using it,
appreciate if some one could help me
thanks

hey, i was trying the below link tutorial
http://support.microsoft.com/kb/316887/EN-US/

but i get an error saying "cannot convert from 'byte[*,*]' to 'byte[]'" in the 8th line of the below code, why is this happening??

and for the 12th line "The best overloaded method match for 'System.IO.Stream.Write(byte[], int, int)' has some invalid arguments"
??

can some one give me a solution to this????

private void SqlBlob2File(string DestFilePath)
        {
            int PictureCol = 0; //  the column # of the BLOB field
            MySqlConnection cn = new MySqlConnection("server=localhost;integrated security=yes;database=NorthWind UId=root;Pwd=8780");
            MySqlCommand cmd = new MySqlCommand("SELECT Picture FROM Categories WHERE CategoryName=\'Test\'", cn);
            cn.Open();
            MySqlDataReader dr = cmd.ExecuteReader();
            dr.Read();
            byte[,] b;
            dr.GetBytes(PictureCol,0,b,0,b.Length);
            dr.Close();
            cn.Close();
            System.IO.FileStream fs = new System.IO.FileStream(DestFilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
            fs.Write(b, 0, b.Length);
            fs.Close();
        }

hi dear
it is not recommended that you save your posted file in database

you must save the file name in a string field like: Pic_url

you must do :

protected void Button1_Click(object sender, EventArgs e)
    {
        //check fileupload has a file or not
        if (FileUpload1.HasFile)
        {
            //save filename as your pic_url field in your DB
            string FileName = FileUpload1.PostedFile.FileName;

            //now use path for physical Address
            string path = Server.MapPath(".");

            //now save your file
            FileUpload1.SaveAs(path + "\\" + FileName);
        }
    }

also you must combine your filename with a random name or datatime for anti duplicate string dateAndtime = DateTime.Now.ToString("yyyyMMddhhmmsstt"); FileName = dateAndtime + FileName;


if you want to check file extention and size please post your question,

Edited 6 Years Ago by kouroshnik: n/a

Attachments fffffff.png 3.29 KB gggggggg.png 4.9 KB

hi dear
it is not recommended that you save your posted file in database

you must save the file name in a string field like: Pic_url

you must do :

protected void Button1_Click(object sender, EventArgs e)
    {
        //check fileupload has a file or not
        if (FileUpload1.HasFile)
        {
            //save filename as your pic_url field in your DB
            string FileName = FileUpload1.PostedFile.FileName;

            //now use path for physical Address
            string path = Server.MapPath(".");

            //now save your file
            FileUpload1.SaveAs(path + "\\" + FileName);
        }
    }

also you must combine your filename with a random name or datatime for anti duplicate
[ATTACH]17984[/ATTACH]

[ATTACH]17985[/ATTACH]

string dateAndtime = DateTime.Now.ToString("yyyyMMddhhmmsstt");
            FileName = dateAndtime + FileName;

if you want to check file extention and size please post your question,

ok so what you are saying is not to post the file into the database? why is it not a good solution?

you had said to only save the file name in the database combined with the datetime for example, where do i save the softcopy in the server??? can you give me more details on this..

This article has been dead for over six months. Start a new discussion instead.