示例#1
0
 public static void DeleteFile(string filename)
 {
     string account = (string)HttpContext.Current.Session["user"].ToString();
     BlobManager blob = new BlobManager();
     blob.DeleteBlob("Temp/" + account + "/" + filename);
     //new Upload<DetailsFile>().PostedFiles.Remove(filename);
 }
 protected void deleteFile(string fname)
 {
     FileInforMa.File_Delete(fileId.Text, fname);
     getFile(fileId.Text);
     BlobManager blobManager = new BlobManager();
     blobManager.DeleteBlob(HiddenFieldCustomerID.Value + "/" + fname);
     if (fileGrid.Rows.Count ==0)
         Server.Transfer("CheckOwnFile.aspx");
 }
        /// <summary>
        /// Delete event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridViewlistUpload_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string count = GridViewlistUpload.Rows[e.RowIndex].Cells[0].Text.ToString();
            string id = GridViewlistUpload.Rows[e.RowIndex].Cells[1].Text.ToString();
            string name = GridViewlistUpload.Rows[e.RowIndex].Cells[2].Text.ToString();

            List<FileInfoMation> list = new List<FileInfoMation>();
            List<FileInfoMation> listOld = new List<FileInfoMation>();
            List<FileInfoMation> listtemp = new List<FileInfoMation>();

            list = (List<FileInfoMation>)ViewState["HashCheckArray"];
            listOld = FileInforMa.File_GetByAll();
            listOld = listOld.Where(c => c.File_Sharing_ID == id).ToList();
            //check value data
            listtemp = listOld.Where(c => c.File_Name == name).ToList();
            if (listtemp.Count > 0)
            {
                FileInforMa.File_Delete(id, name);
                if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "")
                {
                    BlobManager blobManger = new BlobManager();
                    blobManger.DeleteBlob(LabelCustomerName.Text + "/" + name);
                }
                else
                {
                    string customerFoler = Path.Combine(GetMapPath() + Constant.UPLOAD_STORAGE + "\\" + LabelCustomerName.Text);
                    if (File.Exists(customerFoler + "\\" + name))
                    {
                        File.Delete(customerFoler + "\\" + name);
                    }
                }
            }
            else if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "")
            {
                BlobManager blobManger = new BlobManager();
                blobManger.DeleteBlob("Temp/" + HiddenFieldAccount.Value + "/" +  name);
            }

            PostedFiles.Remove(name);
            list = list.Where(c => c.File_Name != name).ToList();

            ViewState.Remove("HashCheckArray");
            ViewState["HashCheckArray"] = list;
            FillGridview(list);
        }
        /// <summary>
        /// ButtonUpload Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButtonUpload_Click(object sender, EventArgs e)
        {
            Dictionary<string, HttpPostedFile> dicPostedFiles = PostedFiles;
            try
            {
                StartUpload(dicPostedFiles);
                List<FileInfoMation> listFile = new List<FileInfoMation>();
                listFile = FileInforMa.File_GetByAll();
                listFile = listFile.Where(c => c.File_Sharing_ID == HiddenFieldID.Value).ToList();
                ViewState.Remove("HashCheckArray");
                ViewState.Add("HashCheckArray", listFile);
                FillGridview(listFile);
            }
            catch (Exception ex)
            {
                ButtonUpload.Enabled = true;
                if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "")
                {
                    BlobManager blobManager = new BlobManager();
                    foreach (string fileName in dicPostedFiles.Keys)
                    {
                        HttpPostedFile postedFile = dicPostedFiles[fileName];
                        if (postedFile == null)
                        {
                            blobManager.DeleteBlob("Temp/" + HiddenFieldAccount.Value + "/" +  fileName);
                        }
                        else
                            blobManager.DeleteBlob(LabelCustomerName.Text + "/" + fileName);
                    }
                }
                else
                {
                    foreach (HttpPostedFile postedFile in dicPostedFiles.Values)
                    {
                        string directoryPath = Server.MapPath("~/" + Constant.UPLOAD_STORAGE + "\\" + LabelCustomerName.Text.Trim() + "\\" + Path.GetFileName(postedFile.FileName));
                        if (File.Exists(directoryPath))
                            File.Delete(directoryPath);

                    }
                }
                logger.Error("Error btnUpload_Click", ex);
                RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("TITLE_ERROR"), ex.Message) + "\");");
            }
        }