protected void Button_delete(object sender, EventArgs e) { ImageButton imageButton = sender as ImageButton; GridViewRow dr = (GridViewRow)imageButton.Parent.Parent; string fileName = ((Label)dr.FindControl("linkFileName")).Text; string path; Dictionary_FileNames.TryGetValue(fileName, out path); Dictionary_FilePathSize.Remove(path); ListFileName.Remove(fileName); Dictionary_FileNames.Remove(fileName); File.Delete(path); BindGridView(); }
protected void ButtonUpload_Click(object sender, EventArgs e) { // 上传,显示,保存此次上传的文件名和路径。 if (FileUpload.HasFile) { string fileName = FileUpload.FileName; string filePath = Server.MapPath("TempFile") + "\\" + DateTime.Now.ToString("yyyyMMddfff") + "_" + FileUpload.FileName; string fileSize = FileUpload.PostedFile.ContentLength.ToString(); string fileType = Path.GetExtension(fileName); if (FileNameExistsInListFileName(fileName)) { Msgbox("File Exists!"); return; } if (!FileTypeIsAllowable(fileType)) { Msgbox("File Type is not allowable!"); return; } try { FileUpload.SaveAs(filePath); List <string> listFileName = new List <string>(); listFileName = ListFileName; listFileName.Add(fileName); this.ListFileName = listFileName; Dictionary_FileNames.Add(fileName, filePath); Dictionary_FilePathSize.Add(filePath, fileSize); BindGridView(); PageRegisterStartupScript("Refresh();"); } catch (Exception ex) { Msgbox("Upload file failed"); } } else { Msgbox("please choose file to upload!"); } }