我上传文件和一些字段项到文档库我已经在该字段中强制要求一个字段,但即使这样我也能上传文件

时间:2014-11-28 23:03:30

标签: sharepoint-2010

SPSecurity.RunWithElevatedPrivileges(委托()             {                 使用(SPSite site = new SPSite(SPContext.Current.Web.Url,SPUserToken.SystemAccount))                 {                     使用(SPWeb web = site.OpenWeb())                     {                         web.AllowUnsafeUpdates = true;

                    SPFolder folder = web.Folders["ContractorDetails"];
                    SPFileCollection filecol = folder.Files;
                    Boolean replaceExistingFiles = true;
                    string filename = System.IO.Path.GetFileName(FileUpload.PostedFile.FileName);
                    byte[] contents = new byte[Convert.ToInt32(FileUpload.PostedFile.ContentLength)];
                    SPFile addedFile = filecol.Add(filename, contents, replaceExistingFiles);
                    SPItem newItem = addedFile.Item;
                    newItem["Title"] = ddlTitle.SelectedValue;
                    newItem["First Name"] = tbFirstName.Text;
                    newItem["Middle Name"] = tbMiddleName.Text;
                    newItem["Last Name"] = tbLastName.Text;
                    newItem["NT User Name"] = tbNtuser.Text;
                    newItem["Contract Firm"] = tbContractFirm.Text;
                    newItem["Employee Type"] = tbEmpType.Text;
                    newItem["Division"] = ddlDivision.SelectedValue;
                    newItem["Location"] = ddlLocation.SelectedValue;
                    newItem["Contract Start Date"] = dateTimeStart.SelectedDate;
                    newItem["Contract End Date"] = dateTimeEnd.SelectedDate;
                    newItem["Project Term"] = Convert.ToInt32(tbProjectTerm.Text);
                   // newItem["Manager"] = PeopleEditor1.t
                    newItem["Comments"] = tbcomments.Text;
                    newItem.Update();
                    addedFile.Update();


                    web.AllowUnsafeUpdates = false;
                }
            }
        });
    }

1 个答案:

答案 0 :(得分:0)

您是否可以尝试从UI上传文件到检查字段是否必须?