该篇章笔者简述下如何解决提升用户权限上传文档到MOSS之后,修改创建者为文档上传的本人(解决这个问题还是用到移花接木。。。)。也许老手一看标题就清楚了,该标题太忽悠人了(因为创建者字段类型为用户或用户组,作为一个只读类型是不让更改的)!但是如果做为新手对创建者栏位不了解的话看到这标题,也许觉得很新鲜,很贴切,并一直埋头苦干想进一切办法把创建者栏位的值改成上传者本人名字。到最后还是以失败告终。为了避免误导,还是以详细截图来说明解决问题的办法来引导新手更好的完成这个烦恼。
首先,用一个只有只读权限的【test03】用户登陆MOSS上传文档(至于如何解决文档上传,新手可参考我前面的文章上传文档至MOSS),可以看到只读权限的用户也拥有了对他自己所上传文档进行编辑,删除的权利。但是创建者就总是为系统管理员(这是因为进行了权限提升之后的结果。。。下面笔者就开始讲解如何干掉这个问题!!!)
用管理员登录(或者拥有可编辑权限的用户登录都OK),打开所在列表,点击【设置】->【文档库设置】
选择【创建栏】
由于系统默认的【创建者】栏位已存在,不允许重复,这里就取名为【作者】,类型选为【单行文本】,要求此栏包含信息选【是】。(记住类型不能再选【用户或用户组】,因为上面也提到了,该类型是只读域,不让赋值。)
点击确定,点击试图【所有文档】,不选中创建者栏位。(依照图例操作)
项目源码:
1<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="FileUploadOnMoss.ascx.cs" Inherits="FileUploadSolution.FileUploadOnMoss" %>
2 <table cellpadding="0" cellspacing="0" style=" border:1px solid; width:250px">
3 <tr>
4 <td style="width:137px; height: 22px;">
5 请选择列表:</td>
6 <td style="border-left:1px solid; height: 22px;">
7 <asp:DropDownList ID="ListTitleNameDrp" runat="server" OnSelectedIndexChanged="ListTitleNameDrp_SelectedIndexChanged"
8 AutoPostBack="True" Width="105px">
9 </asp:DropDownList></td>
10 </tr>
11 <tr>
12 <td style="width:137px;border-top:1px solid;">
13 请选择文件夹:</td>
14 <td style="border-top:1px solid; border-left:1px solid">
15 <asp:DropDownList ID="FolderNameDrp" runat="server" AutoPostBack="True" Width="104px">
16 </asp:DropDownList></td>
17 </tr>
18 <tr style="border-top:1px solid;">
19 <td colspan="2" style="height: 24px;">
20 <asp:FileUpload ID="FileUpload1" runat="server" Width="240px" /></td>
21 </tr>
22 <tr style="border-top:1px solid;">
23 <td colspan="2">
24 <asp:Button ID="UploadButton" runat="server" OnClick="UploadButton_Click" Text="Upload file" /><asp:Label ID="UploadStatusLabel" runat="server" ForeColor="Red"></asp:Label>
25 </td>
26 </tr>
27</table>
28<hr />
29
2 <table cellpadding="0" cellspacing="0" style=" border:1px solid; width:250px">
3 <tr>
4 <td style="width:137px; height: 22px;">
5 请选择列表:</td>
6 <td style="border-left:1px solid; height: 22px;">
7 <asp:DropDownList ID="ListTitleNameDrp" runat="server" OnSelectedIndexChanged="ListTitleNameDrp_SelectedIndexChanged"
8 AutoPostBack="True" Width="105px">
9 </asp:DropDownList></td>
10 </tr>
11 <tr>
12 <td style="width:137px;border-top:1px solid;">
13 请选择文件夹:</td>
14 <td style="border-top:1px solid; border-left:1px solid">
15 <asp:DropDownList ID="FolderNameDrp" runat="server" AutoPostBack="True" Width="104px">
16 </asp:DropDownList></td>
17 </tr>
18 <tr style="border-top:1px solid;">
19 <td colspan="2" style="height: 24px;">
20 <asp:FileUpload ID="FileUpload1" runat="server" Width="240px" /></td>
21 </tr>
22 <tr style="border-top:1px solid;">
23 <td colspan="2">
24 <asp:Button ID="UploadButton" runat="server" OnClick="UploadButton_Click" Text="Upload file" /><asp:Label ID="UploadStatusLabel" runat="server" ForeColor="Red"></asp:Label>
25 </td>
26 </tr>
27</table>
28<hr />
29
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using Microsoft.SharePoint;
12using System.IO;
13
14 namespace FileUploadSolution
15 {
16 public partial class FileUploadOnMoss : System.Web.UI.UserControl
17 {
18 protected void Page_Load(object sender, EventArgs e)
19 {
20 if(!IsPostBack)
21 {
22 BindListTitle();
23 }
24 }
25 //上传按钮事件
26 protected void UploadButton_Click(object sender, EventArgs e)
27 {
28 Boolean fileOK = false;
29 string fileurl = FileUpload1.PostedFile.FileName;
30 string filename=FileUpload1.FileName;
31 SPWeb web = SPContext.Current.Web;
32 string pathToCheckUrl = string.Empty;
33 string pathToCheck = string.Empty;
34 if (FolderNameDrp.SelectedValue!="")
35 {
36 pathToCheckUrl= web.Lists[ListTitleNameDrp.SelectedValue].RootFolder.SubFolders[FolderNameDrp.SelectedValue].Url;
37 }
38 else
39 {
40 pathToCheckUrl = web.Lists[ListTitleNameDrp.SelectedValue].RootFolder.Url;
41 }
42 pathToCheck = pathToCheckUrl +'/'+ filename;//获取文件所在的路径
43
44 if (FileUpload1.HasFile)//判断上传文件是否加载了文件源
45 {
46 String fileExtension =System.IO.Path.GetExtension(filename).ToLower();
47 //获取文件后缀名名与自行规定的文件类型进行匹配
48 String[] allowedExtensions =
49 { ".doc", ".docx", ".pptx", ".xlsx", ".ppt" };
50 for (int i = 0; i < allowedExtensions.Length; i++)
51 {
52 if (fileExtension == allowedExtensions[i])
53 {
54 fileOK = true;
55 }
56 }
57 }
58 if (fileOK)
59 {
60 try
61 {
62 if (System.IO.File.Exists(pathToCheck))//检索同目录下是否已存在了相同的文件名
63 {
64 //throw new ArgumentException(String.Format("{0} 该文件名已经存在!", filename), "filename");
65 }
66 else
67 {
68 FileUpload(fileurl, filename);
69 UploadStatusLabel.Text = "上传成功!";
70 }
71 }
72 catch
73 { //当同个目录下存在同名文件时,做出错误的提示!
74 UploadStatusLabel.Text = "上传失败!该文件名已存在!";
75
76 }
77 }
78 else
79 {
80 UploadStatusLabel.Text = "抱歉!系统不支持你所上传的文档类型";
81 }
82
83
84 }
85 //绑定当前站点所有列表的标题
86 public void BindListTitle()
87 {
88 SPWeb web = SPContext.Current.Web;
89 string text = "====请选择====";
90 string value = string.Empty;
91 ListTitleNameDrp.Items.Add(new ListItem(text, value));
92 foreach (SPList MyList in web.Lists)
93 { //取得网站中所有列表的标题,绑定到列表下拉框
94
95 ListTitleNameDrp.Items.Add(MyList.Title);
96 }
97
98 }
99 //绑定指定列表下的文件名
100 protected void ListTitleNameDrp_SelectedIndexChanged(object sender, EventArgs e)
101
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using Microsoft.SharePoint;
12using System.IO;
13
14 namespace FileUploadSolution
15 {
16 public partial class FileUploadOnMoss : System.Web.UI.UserControl
17 {
18 protected void Page_Load(object sender, EventArgs e)
19 {
20 if(!IsPostBack)
21 {
22 BindListTitle();
23 }
24 }
25 //上传按钮事件
26 protected void UploadButton_Click(object sender, EventArgs e)
27 {
28 Boolean fileOK = false;
29 string fileurl = FileUpload1.PostedFile.FileName;
30 string filename=FileUpload1.FileName;
31 SPWeb web = SPContext.Current.Web;
32 string pathToCheckUrl = string.Empty;
33 string pathToCheck = string.Empty;
34 if (FolderNameDrp.SelectedValue!="")
35 {
36 pathToCheckUrl= web.Lists[ListTitleNameDrp.SelectedValue].RootFolder.SubFolders[FolderNameDrp.SelectedValue].Url;
37 }
38 else
39 {
40 pathToCheckUrl = web.Lists[ListTitleNameDrp.SelectedValue].RootFolder.Url;
41 }
42 pathToCheck = pathToCheckUrl +'/'+ filename;//获取文件所在的路径
43
44 if (FileUpload1.HasFile)//判断上传文件是否加载了文件源
45 {
46 String fileExtension =System.IO.Path.GetExtension(filename).ToLower();
47 //获取文件后缀名名与自行规定的文件类型进行匹配
48 String[] allowedExtensions =
49 { ".doc", ".docx", ".pptx", ".xlsx", ".ppt" };
50 for (int i = 0; i < allowedExtensions.Length; i++)
51 {
52 if (fileExtension == allowedExtensions[i])
53 {
54 fileOK = true;
55 }
56 }
57 }
58 if (fileOK)
59 {
60 try
61 {
62 if (System.IO.File.Exists(pathToCheck))//检索同目录下是否已存在了相同的文件名
63 {
64 //throw new ArgumentException(String.Format("{0} 该文件名已经存在!", filename), "filename");
65 }
66 else
67 {
68 FileUpload(fileurl, filename);
69 UploadStatusLabel.Text = "上传成功!";
70 }
71 }
72 catch
73 { //当同个目录下存在同名文件时,做出错误的提示!
74 UploadStatusLabel.Text = "上传失败!该文件名已存在!";
75
76 }
77 }
78 else
79 {
80 UploadStatusLabel.Text = "抱歉!系统不支持你所上传的文档类型";
81 }
82
83
84 }
85 //绑定当前站点所有列表的标题
86 public void BindListTitle()
87 {
88 SPWeb web = SPContext.Current.Web;
89 string text = "====请选择====";
90 string value = string.Empty;
91 ListTitleNameDrp.Items.Add(new ListItem(text, value));
92 foreach (SPList MyList in web.Lists)
93 { //取得网站中所有列表的标题,绑定到列表下拉框
94
95 ListTitleNameDrp.Items.Add(MyList.Title);
96 }
97
98 }
99 //绑定指定列表下的文件名
100 protected void ListTitleNameDrp_SelectedIndexChanged(object sender, EventArgs e)
101