对Document library中修改文档的Author之实现修改在list(三)

背景:
       接上篇。

分析:
       1,传入三个参数: listId, 修改全部/修改选中,选中的itemId。
       2,修改之前先checkout, 然后记录修改的信息。

实现:

1, 用javascript弹出一个modalDialog窗口:
Code
function GotoEditAuthor(Mode,ListId)
{
    
var DocumentIds = GetSelectedItems("DocumentID"",");
    
var handle = window.showModalDialog('/_layouts/EditAuthorFolder/EditAuthor.aspx?Mode=' + Mode + '&listItems=' + DocumentIds + '&listID=' + ListId, window,'status:off;center=yes;edge:raised;dialogHeight:400px;dialogWidth:450px;help:0;resizable:0;scrollbar=0');
    
if (handle != null && handle != '' && typeof handle != 'undefined'
    
{
        window.location.href
=window.location.href;
    }
    
}

2,  修改的代码:
Code
        using (mySite = SPContext.Current.Site)
        
{
            
using (myWeb = mySite.OpenWeb(strWebName))
            
{
                
// 是否存在用户
                try
                
{
                    DocAuthor 
= myWeb.AllUsers[TextBoxAuthor.Text];
                }

                
catch
                
{
                    DocAuthor 
= null;
                }

                
if  (DocAuthor != null)
                
{
                    SPDocumentLibrary myDocLibrary 
= myWeb.Lists[myDocGuid] as SPDocumentLibrary;
                    SPListItemCollection myDocItems;
                    myWeb.AllowUnsafeUpdates 
= true;
                    
// Mode == 0 is update selected document author;
                    
// Mode == 1 is update all document author;
                    if (Mode == 0)
                    
{
                        
string[] arrDocID = Regex.Split(strDocItems, ",");
                        
foreach (string myDocID in arrDocID)
                        
{
                            
int DocID;
                            
try
                            
{
                                DocID 
= int.Parse(myDocID);
                            }

                            
catch
                            
{
                                DocID 
= 0;
                            }

                            
if (DocID != 0)
                            
{
                                SPListItem myItem 
= myDocLibrary.Items.GetItemById(DocID);
                                SPFile myFile 
= myItem.File;
                                myFile.CheckOut();
                                myItem[
"Owner"= DocAuthor;
                                myItem.Update();
                                myFile.CheckIn(System.DateTime.Today.ToShortDateString() 
+ ": Comment: Update document author ");                                  
                            }

                          
                        }

                    }

                    
else if (Mode == 1)
                    
{
                        myDocItems 
= myDocLibrary.Items;
                        
foreach (SPListItem myItem in myDocItems)
                        
{
                            SPFile myFile 
= myItem.File;
                            myFile.CheckOut();
                            myItem[
"Owner"= DocAuthor;
                            myItem.Update();
                            myFile.CheckIn(System.DateTime.Today.ToShortDateString() 
+ "Comment: Update document author ");
                        }

                    }

                    myWeb.AllowUnsafeUpdates 
= false;
                    CloseWindow(
true);
                }

                
else
                
{
                    LabelMessage.Text 
= "The User not found! Plese change another one.";
                }

            }

        }

3,   关闭窗口
Code
    private void CloseWindow(bool IsDirty)
    
{
        Response.Write(
string.Format("<SCRIPT>top.returnValue = {0}; window.close();<" + "/SCRIPT>", (IsDirty ? "1" : "null")));
        Response.End();
    }
 

效果:

转载于:https://www.cnblogs.com/lmkong/archive/2008/09/08/1286859.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值