Ajax Multiple File Upload
<div style="height: 43px">
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" Height="30px"
onuploadcomplete="AjaxFileUpload1_UploadComplete1" Width="614px"
MaximumNumberOfFiles="10"
ThrobberID="throbber"
AllowedFileTypes="jpg,jpeg,gif,png" style="margin-top: 6px" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
.cs code
protected void AjaxFileUpload1_UploadComplete1(object sender, AjaxFileUploadEventArgs e)
{
string path = Server.MapPath("");
string bpath = path + "//" + "Image" + "//"+ e.FileName;
AjaxFileUpload1.SaveAs(bpath);
string s = "Image" + "/" + e.FileName;
string str = "insert into upload1 values('" + s + "')";
cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
**********
Ajax single file upload
<ajax:ToolkitScriptManager ID="scriptManager1" runat="server"/>
<div>
<ajax:AsyncFileUpload ID="fileUpload1" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError"
CompleteBackColor="White" Width="350px" runat="server" UploaderStyle="Modern" UploadingBackColor="#CCFFFF"
ThrobberID="imgLoad" OnUploadedComplete="fileUploadComplete" /><br />
<asp:Image ID="imgLoad" runat="server" ImageUrl="loading.gif" />
<br />
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
.cs code
string filename = fileUpload1.FileName;
string path = Server.MapPath("");
string bpath =path+ "/" + "Image" + "/" + filename;
fileUpload1.SaveAs(bpath);
//insert path in database
string s = "~" + "/" + "Image" + "/" + filename;
string str = "insert into upload1 values('" + s + "')";
cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Record saved!')</script>");
<div style="height: 43px">
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" Height="30px"
onuploadcomplete="AjaxFileUpload1_UploadComplete1" Width="614px"
MaximumNumberOfFiles="10"
ThrobberID="throbber"
AllowedFileTypes="jpg,jpeg,gif,png" style="margin-top: 6px" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
.cs code
protected void AjaxFileUpload1_UploadComplete1(object sender, AjaxFileUploadEventArgs e)
{
string path = Server.MapPath("");
string bpath = path + "//" + "Image" + "//"+ e.FileName;
AjaxFileUpload1.SaveAs(bpath);
string s = "Image" + "/" + e.FileName;
string str = "insert into upload1 values('" + s + "')";
cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
**********
Ajax single file upload
<ajax:ToolkitScriptManager ID="scriptManager1" runat="server"/>
<div>
<ajax:AsyncFileUpload ID="fileUpload1" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError"
CompleteBackColor="White" Width="350px" runat="server" UploaderStyle="Modern" UploadingBackColor="#CCFFFF"
ThrobberID="imgLoad" OnUploadedComplete="fileUploadComplete" /><br />
<asp:Image ID="imgLoad" runat="server" ImageUrl="loading.gif" />
<br />
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
.cs code
string filename = fileUpload1.FileName;
string path = Server.MapPath("");
string bpath =path+ "/" + "Image" + "/" + filename;
fileUpload1.SaveAs(bpath);
//insert path in database
string s = "~" + "/" + "Image" + "/" + filename;
string str = "insert into upload1 values('" + s + "')";
cmd = new SqlCommand(str, con);
con.Open();
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Record saved!')</script>");
No comments:
Post a Comment