Пример #1
0
        protected void btnAddFile_Click(object sender, EventArgs e)
        {
            lblMsg.Text = "";

            if (lblSelectedFolder.Text.Trim() != "-")
            {
                if (gvFiles.SelectedIndex < 0)
                {
                    if (!fuFileUpload.HasFile && txtFileURLExt.Text.Trim().Length == 0)
                    {
                        lblMsg.Text = "Please attach your file or specify the file name in the external url text field.";
                        return;
                    }
                    else if (fuFileUpload.HasFile && txtFileURLExt.Text.Trim().Length > 0)
                    {
                        lblMsg.Text = "Please only attach your file OR specify the file name in your external url, not both.";
                        return;
                    }
                }
            }
            else
            {
                lblMsg.Text = "You Cannot Upload file at root Folder!";
                return;
            }

            if (fuFileUpload.HasFile)
            {
                int filesz = fuFileUpload.PostedFile.ContentLength / 1024;
                if (filesz > 10240)
                {
                    lblMsg.Text = "File Size cannot exceed 10MB!";
                    return;
                }
            }

            string filename = null;
            string fileurl = "";

            if (fuFileUpload.HasFile)
            {
                filename = fuFileUpload.FileName.Replace(" ", "_");
            }
            else
            {
                fileurl = txtFileURLExt.Text.Trim();
                filename = fileurl.Substring(fileurl.LastIndexOf("/") + 1);
            }

            if (filename.Length > 250)
            {
                lblMsg.Text = "File Name cannot exceed 250 character!";
                return;
            }

            ArtefactClient arClient = new ArtefactClient();
            try
            {
                if (hidFile.Value == "")
                {
                    //Upload New file
                    arClient.UploadFile(NUSNetUser(), EventID(), lblSelectedFolder.Text.Trim(), filename, txtFileDesc.Text.Trim(), fileurl);

                    if (fuFileUpload.HasFile)
                    {
                        UploadFile(filename);
                    }

                    loadFiles(lblSelectedFolder.Text.Trim());
                    lblMsg.Text = "Upload Success";
                }
                else
                {
                    WorkspaceFiles wrkFile = arClient.GetWorkSpaceFile(NUSNetUser(), EventID(), lblSelectedFolder.Text.Trim(), hidFile.Value);

                    arClient.UpdateFile(NUSNetUser(), EventID(), lblSelectedFolder.Text.Trim(), hidFile.Value, txtFileDesc.Text.Trim(), fileurl);
                    lblMsg.Text = "Update Success";

                }

                txtFileDesc.Text = "";
                txtFileURLExt.Text = "";
                loadFiles(lblSelectedFolder.Text.Trim());
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
                if (hidFile.Value == "")
                    lblMsg.Text = "Upload Failed";
                else
                    lblMsg.Text = "Update Failed";
            }
            finally
            {
                arClient.Close();
            }
        }
Пример #2
0
        protected void gvFiles_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                int index = int.Parse(e.CommandArgument.ToString());

                string fileID = ((Label)gvFiles.Rows[index].Cells[2].FindControl("lblFileName")).Text.Replace(" ", "%20");

                string filepath = workSpaceDir(lblSelectedFolder.Text.Trim()) + "\\" + ((Label)gvFiles.Rows[index].Cells[2].FindControl("lblFileName")).Text;
                ArtefactClient arClient = new ArtefactClient();
                try
                {
                    WorkspaceFiles wrkFile = arClient.GetWorkSpaceFile(NUSNetUser(), EventID(), lblSelectedFolder.Text.Trim(), fileID);

                    if (wrkFile.UploadedBy == NUSNetUser().UserID)
                    {
                        arClient.DeleteFile(NUSNetUser(), EventID(), lblSelectedFolder.Text.Trim(), fileID);

                        if (filepath.Contains("\\WorkSpace\\"))
                        {
                            if (System.IO.File.Exists(filepath))
                            {
                                System.IO.File.Delete(filepath);
                            }
                        }
                        lblMsg.Text = "File Successfully removed!";
                        txtFileDesc.Text = "";
                        txtFileURLExt.Text = "";
                        loadFiles(lblSelectedFolder.Text.Trim());
                    }
                    else
                    {
                        lblMsg.Text = "You can only delete what is belong to you!";
                    }
                }
                catch (Exception)
                {
                    lblMsg.Text = "File Failed to remove!";
                }
                finally
                {
                    arClient.Close();
                }

                //loadFiles(classId, folderID);
            }
        }