mmiinnooo
جمعه 23 مرداد 1394, 01:56 صبح
سلام
من می خوام تو سایت آپلود فایل قرار بدم .. به طوری که
هر فایلی که کاربر آپلود میکنه را لیست کنه نشون بده و اگر کاربر خواست هر کدوم و حذف کنه
خواهش می کنم کمکم کنید امروز خیلی تو نت در این مورد گشتم
کدی که نوشتم به صورت زیره ولی هر بار که روی آپلود کلیک می شه نام فایل قبلی پاک یشه
<script type="text/javascript">
window.onsubmit = function () {
if (Page_IsValid) {
var updateProgress = $find("<%= UpdateProgress1.ClientID %>");
window.setTimeout(function () {
updateProgress.set_visible(true);
}, 100);
}
}
</script>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="modal">
<div class="center">
<asp:Label ID="Label1" runat="server" Text="لطفا چند لحظه صبر کنید..."></asp:Label>
<img alt="" src="../images/forDesign/loading.png" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Table ID="tableFileList" runat="server"></asp:Table>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="margin: 20px" >
<asp:FileUpload ID="FileUpload1" runat="server" ValidationGroup="selectFile"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="لطفا فایل را انتخاب نمائید" ControlToValidate="FileUpload1"
runat="server" ForeColor="Red" ValidationGroup="selectFile"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="btnUpload" Text="Submit" runat="server" ValidationGroup="selectFile" OnClick="Upload" />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
protected void Upload(object sender, EventArgs e)
{
string fileName = System.IO.Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/Uploads/") + fileName);
TableRow r = new TableRow();
tableFileList.Rows.Add(r);
TableCell c1 = new TableCell();
r.Cells.Add(c1);
TableCell c2 = new TableCell();
r.Cells.Add(c2);
c1.Text = fileName;
Button btndelete = new Button();
btndelete.Text = "حذف";
btndelete.Click += new EventHandler(this.btndelete_Click);
btndelete.ValidationGroup = "s";
c2.Controls.Add(btndelete);
TableCell c3 = new TableCell();
r.Cells.Add(c3);
long length = FileUpload1.FileContent.Length;
int lengthK = (int)(length / 1024);
c3.Text = lengthK.ToString() + " کیلو بایت";
}
protected void btndelete_Click(object sender, EventArgs e){
}
من می خوام تو سایت آپلود فایل قرار بدم .. به طوری که
هر فایلی که کاربر آپلود میکنه را لیست کنه نشون بده و اگر کاربر خواست هر کدوم و حذف کنه
خواهش می کنم کمکم کنید امروز خیلی تو نت در این مورد گشتم
کدی که نوشتم به صورت زیره ولی هر بار که روی آپلود کلیک می شه نام فایل قبلی پاک یشه
<script type="text/javascript">
window.onsubmit = function () {
if (Page_IsValid) {
var updateProgress = $find("<%= UpdateProgress1.ClientID %>");
window.setTimeout(function () {
updateProgress.set_visible(true);
}, 100);
}
}
</script>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="modal">
<div class="center">
<asp:Label ID="Label1" runat="server" Text="لطفا چند لحظه صبر کنید..."></asp:Label>
<img alt="" src="../images/forDesign/loading.png" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Table ID="tableFileList" runat="server"></asp:Table>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="margin: 20px" >
<asp:FileUpload ID="FileUpload1" runat="server" ValidationGroup="selectFile"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="لطفا فایل را انتخاب نمائید" ControlToValidate="FileUpload1"
runat="server" ForeColor="Red" ValidationGroup="selectFile"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="btnUpload" Text="Submit" runat="server" ValidationGroup="selectFile" OnClick="Upload" />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
</asp:UpdatePanel>
protected void Upload(object sender, EventArgs e)
{
string fileName = System.IO.Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/Uploads/") + fileName);
TableRow r = new TableRow();
tableFileList.Rows.Add(r);
TableCell c1 = new TableCell();
r.Cells.Add(c1);
TableCell c2 = new TableCell();
r.Cells.Add(c2);
c1.Text = fileName;
Button btndelete = new Button();
btndelete.Text = "حذف";
btndelete.Click += new EventHandler(this.btndelete_Click);
btndelete.ValidationGroup = "s";
c2.Controls.Add(btndelete);
TableCell c3 = new TableCell();
r.Cells.Add(c3);
long length = FileUpload1.FileContent.Length;
int lengthK = (int)(length / 1024);
c3.Text = lengthK.ToString() + " کیلو بایت";
}
protected void btndelete_Click(object sender, EventArgs e){
}