This is a migrated thread and some comments may be shown as answers.

when use radupload control in ascx control issue

0 Answers 64 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Priya Priya
Top achievements
Rank 1
Priya Priya asked on 09 Oct 2009, 11:11 AM

hi!
     I upload a file to database using below code...the below code is performed well in aspx page...but I want this in usercontrol that is ascx page...when use this code in ascx control , if i press upload button, can not get uploaded file in for loop(below bolded line)..so , for loop inner statement does not executed..So i cannot insert Image file into database..can anyone help me? thanks


Radupload control

 

 

<asp:TextBox ID="txtName" runat="server"></asp:TextBox>

 

 

<telerik:RadUpload ID="FileUpload1" Runat="server"/><br/>

 

 

<br />

 

 

<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" /><br />

 

 

<br />

 

 

<asp:Label ID="lblMessage" runat="server"></asp:Label><br />

 

 

 

btnupload click event
protected
void btnUpload_Click(object sender, EventArgs e)

 

{

 

foreach (UploadedFile file in FileUpload1.UploadedFiles)

 

{

 

byte[] bytes = new byte[file.InputStream.Length];

 

file.InputStream.Read(bytes, 0, (

int)(file.InputStream.Length));

 

 

string strImageName = txtName.Text.ToString();

 

 

 

// Create SQL Connection

 

 

SqlConnection con = new SqlConnection();

 

con.ConnectionString =

ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

 

 

// Create SQL Command

 

 

SqlCommand cmd = new SqlCommand();

 

cmd.CommandText =

"Ins_Files";

 

cmd.CommandType =

CommandType.StoredProcedure;

 

cmd.Connection = con;

 

SqlParameter ImageName = new SqlParameter("@ImageName", SqlDbType.VarChar, 50);

 

ImageName.Value = strImageName.ToString();

cmd.Parameters.Add(ImageName);

 

SqlParameter UploadedImage = new SqlParameter("@Image", SqlDbType.Image, bytes.Length);

 

UploadedImage.Value = bytes;

cmd.Parameters.Add(UploadedImage);

con.Open();

 

int result = cmd.ExecuteNonQuery();

 

con.Close();

 

if (result > 0)

 

lblMessage.Text =

"File Uploaded";

 

 

}

No answers yet. Maybe you can help?

Tags
Upload (Obsolete)
Asked by
Priya Priya
Top achievements
Rank 1
Share this question
or