ASP.NET - how to make upload files like below in grid??

Asked By mani on 27-Jan-12 01:48 AM
hi..i have exefiles to upload with many forlders..and i need to display like this in my grid..like this..any help??

http://www.gsmfilehosting.com/users/gsmfileserver
Jitendra Faye replied to mani on 27-Jan-12 04:00 AM

Follow these steps-

step1: Take one File Uplaod control in GridView ItemTemplate like this-

<


ItemTemplate>

<


asp:FileUpload ID="FileUpload2" runat="server" />

</


ItemTemplate>


Step2: Now Implement GridView_RowUpdating event like this-

protected


void gridView_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

GridViewRow


row = gridView.Rows[e.RowIndex];

//SUPPOSE fILE Upload control is in cell 0 of GridView.

FileUpload


fileUpload = row.Cells[0].FindControl("fileUpload1") as FileUpload;

if


(fileUpload != null && fileUpload.HasFile)

{

fileUpload.SaveAs(Server.MapPath(

"images/hardware/" + fileUpload.FileName));

}

}


TRY THIS CODE AND LET ME KNOW.

dipa ahuja replied to mani on 27-Jan-12 07:48 AM
<script type="text/javascript">
var counter = 0;
function AddFileUpload()
{
    var div = document.createElement('DIV');
    div.innerHTML = '<input id="file' + counter + '" name = "file' + counter + '" type="file" /><input id="Button' + counter + '" type="button" value="Remove" onclick = "RemoveFileUpload(this)" />';
    document.getElementById("FileUploadContainer").appendChild(div);
    counter++;
}
function RemoveFileUpload(div)
{
    document.getElementById("FileUploadContainer").removeChild(div.parentNode);
}
</script>
 
<span style="font-family: Arial">Click to add files</span>&nbsp;&nbsp;
<input id="Button1" type="button" value="add" onclick="AddFileUpload()" />
 
<div id="FileUploadContainer">
  <!--FileUpload Controls will be added here -->
</div>
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
 
.CS Code
protected void btnUpload_Click(object sender, EventArgs e)
{
  for (int i = 0; i < Request.Files.Count; i++)
  {
    HttpPostedFile PostedFile = Request.Files[i];
    if (PostedFile.ContentLength > 0)
    {
      string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
      PostedFile.SaveAs(Server.MapPath("temp\\") + FileName);
    }
  }
}