zoukankan      html  css  js  c++  java
  • 从备份中恢复被用户误删的sharepoint 2003的Doc Library。

    在sharepoint 2003中因为没有回收功能,恢复被用户误删得文件相当麻烦。
    一般的途径是恢复sql2000的备份,重新安装一个sharepoint 2003,用一个偷梁换柱的办法(修改GUID)把新的sharepoint2003连接回sql2000的备份。然后取回文件。

    其实有一个更加简单办法。
    因为所有的文件均存放在docs表中,使用以下的代码就可以把文件取回本地

    string connectionString = @"Data Source=<SQL2000 Server Name>;Initial Catalog=<Database Name>;Integrated Security=True";
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();

                //This section is to obtain the total number of files
                //SQL query string: dirname = folder from which you would like to retrieve from
                //extension<>'' = must have extension = must be a file
                //size >0 = size of file must not be NULL
                SqlCommand cmd0 = new SqlCommand(@"select count(*) from docs where dirname like '%lrts/shared%' and extension <>'' and size >0 ", conn);
                SqlDataReader reader0 = cmd0.ExecuteReader();
                reader0.Read();
                string totalItems = reader0[0].ToString();
                reader0.Close();
                int itemNums = Int32.Parse(totalItems);

                //This section retrieves all the Id of the files and places them in a ArrayList
                SqlCommand cmd1 = new SqlCommand(@"select Id, DirName, LeafName, Size from docs where dirname like '%<DocLib Path>%' and extension <>'' and size >0 ", conn);
                SqlDataReader reader1 = cmd1.ExecuteReader();
                ArrayList allID = new ArrayList();

                for (int i = 0; i < itemNums; i++)
                {
                    reader1.Read();

                    string IDNumber = reader1["Id"].ToString();
                    allID.Add(IDNumber);
                }
                reader1.Close();

                //This section retrieves all files
                for (int i = 0; i < itemNums; i++)
                {
                    string IDNumber = (string)allID[i];     //getting Id

                    SqlCommand cmd = new SqlCommand(@"select Id, DirName, LeafName, Size, Content from docs where dirname like '%lrts/shared%' and extension <>''  and size >0 and Id='" + IDNumber + "'", conn);

                    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);

                    if (reader.HasRows)
                    {
                        reader.Read();

                        //set the content length to the stored content length in the DB
                        String ContentLength = reader["Size"].ToString();

                        String dirName = reader["DirName"].ToString();

                        //creating directory structure from dirName
                        Directory.CreateDirectory(@"C:\retrieve docs\" + dirName);

                        //place the file in this dir
                        string pathName = @"C:\retrieve docs\" + dirName + @"\";

                        //getting the filename
                        String fileName = reader["LeafName"].ToString();

                        //read out the binary data from the db
                        byte[] data = reader["Content"] as byte[];

                        MemoryStream memstream = new MemoryStream();

                        memstream.Write(data, 0, Int32.Parse(ContentLength));

                        byte[] byteArray = memstream.ToArray();

                        memstream.Flush();
                        memstream.Close();

                        FileStream fs = File.Create(pathName + fileName);
                        BinaryWriter bw = new BinaryWriter(fs);

                        bw.Write(byteArray);
                        bw.Close();
                        fs.Close();

                        reader.Close();

     

                    }
                }
            }


    这个方法很快就拿到了文件,当然,用户的权限就没有办法取回了。

  • 相关阅读:
    leetcode 287 寻找重复数
    739 每日温度 && 单调栈算法的思路
    leetcode 34 在排序数组中查找元素的第一个和最后一个位置
    leetcode 239 滑动窗口最大值
    leetcode 114 二叉树展开为链表
    leetcode 79 单词搜索
    leetcode 88 合并两个有序数组
    函数指针 & 指针函数
    leetcode 240 搜索二维矩阵
    谱聚类
  • 原文地址:https://www.cnblogs.com/by1455/p/1032419.html
Copyright © 2011-2022 走看看