Hi Sir,
I have a doubt...
If a user is uploading files on the dynamic file upload controls by mistake he selectes one file more than once and it gets uploaded to a temp location only once but whereas in the girdview it displays more than once and when the user clicks on the download on the repeated files it those a error is thr is any way so that the user selcts the files only once....
Are you confortable of the what I'm asking...
<asp:Content ID="Content1" ContentPlaceHolderID="cphWorkArea" Runat="Server">
<h1 class="main-heading" style="height: 9px; margin-left: 521px; width: 368px;">Welcome to Multi-Upload </h1>
<p style="width: 203px; height: 0px; margin-left: 1040px">
Welcome
<asp:Label ID="user" runat="server" Font-Size="Medium"></asp:Label>
<span style="font-family:Arial"><span style="color: #003366"> <asp:Button ID="logout" runat="server" onclick="logout_Click" Text="Logout" />
</span></span><br />
</p>
<h1 class="main-heading" style="height: 1px; margin-left: 521px; width: 374px;"> </h1>
<div id="upload" runat="server">
<p style="width: 389px; height: 53px; margin-left: 480px">
<br /><br />
</p>
<div id = "FileUploadContainer">
<!--FileUpload Controls will be added here -->
</div>
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
<br />
<br />
</div>
<br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" BackColor="#EBEBEB"
AutoGenerateColumns="False" CssClass="full-width grid" Height="268px"
Width="663px">
<HeaderStyle BackColor="#CCCCCC" />
<AlternatingRowStyle BackColor="#F7F7F7" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="File Name" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center"
HeaderText="Link to download">
<ItemTemplate>
<asp:LinkButton ID="lnkDownload" runat="server" OnClick="DownloadFile"
Text='<%# Eval("Path") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="IsExists" HeaderText="Status" />
</Columns>
</asp:GridView>
<br />
</asp:Content>
protected void btnUpload_Click(object sender, EventArgs e)
{
List<ListItem> files = new List<ListItem>();
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);
string Ext = System.IO.Path.GetExtension(FileName);
if ((Ext == ".pptx"))
{
PostedFile.SaveAs(Server.MapPath("~/Temp/") + FileName);
string[] filePaths = Directory.GetFiles(Server.MapPath("Files\\"));
string isExists = string.Empty;
DataTable dt = new DataTable();
if (ViewState["Table"] == null)
{
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Name",typeof(string)),
new DataColumn("Path",typeof(string)),
new DataColumn("IsExists",typeof(string))});
}
else
{
dt = (DataTable)ViewState["Table"];
}
isExists = File.Exists(Server.MapPath("~/Files/") + FileName) ? "Already exists" : "New";
dt.Rows.Add(FileName, string.Format("~/Temp/{0}", FileName), isExists);
ViewState["Table"] = dt;
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
//string filePath = Server.MapPath("Files\\") + FileName;
//files.Add(Path.GetFileName(FileName), filePath);
// files.Add(new ListItem(Path.GetFileName(FileName), filePath));
server.Visible = true;
upload.Visible = false;
}
else
{
Response.Write(@"<script language='javascript'>alert('Error in uploading: \n" + FileName + " .');</script>");
}
}
}
}