使用SQL直接从sps数据库中恢复文档

来源:互联网 发布:超牛数据恢复安卓版 编辑:程序博客网 时间:2024/06/15 15:09
 

我的一个客户误删除了一个项目站点,其中有大量的文档需要恢复。由于,这个站点构建在他的SPS之下,而他们的sps数据库非常大,我费了一天的时间将他前天的数据库备份恢复到另一个数据库服务器上。我在试图重新架设一个同样的门户时遇到了一些问题,于是,我想,是否通过sql直接送库中恢复文档来得更加直接

sps的文档都存放在***_SITE数据库的docs表中,表中dirname字段存放了站点的URL后边的部分,leafname则存放的是文件或文件夹的名称,content中存放的是文件的内容,type中标识了该条目是文件还是文件夹(0表示是文件,1表示是文件夹),于是,我编写了一段代码对这个文档库下的文档进行恢复:

        string strFilesID="";

int nCount=0;

 

System.Data.SqlClient.SqlCommand myCmm=new SqlCommand();

myCmm.Connection=sqlConnection2;

myCmm.CommandText="select dirname,leafname,content from docs where dirname like '%%projectserver_120/doclib%%' and type='0'";

myCmm.Connection.Open();

 

System.Data.SqlClient.SqlDataReader myReader;

byte[] MyData=new byte [0];

try

{

myReader=myCmm.ExecuteReader();

while (myReader.Read() )

{

nCount=nCount+1;

 

string strFileName="";

string strFolderId="";

//

string strFolderName="dev";

string strPath=@"d:/guangzhou/";

//

strPath=@"h:/test/";

strFileName=myReader.GetString(1);

 

{

strFolderId=myReader.GetString(0).ToString();

strFilesID=strFolderId;

//

strFolderName=strFolderName+strFolderId;

//

strPath=strPath+strFolderName;

strPath=strPath + strFolderId;

Directory.CreateDirectory(strPath);

strPath=strPath+@"/"+strFileName;

MyData=(byte[])myReader.GetValue(2);

int ArraySize=new int();

ArraySize=MyData.GetUpperBound(0);

if (ArraySize>=0)

{

FileStream fs=new FileStream(@strPath,@FileMode.OpenOrCreate,FileAccess.Write);

fs.Write(MyData,0,ArraySize);

fs.Close();

}

else

{

//eventLog1.WriteEntry ();

string strMyLogName="BatUploadApp";

if (!EventLog.SourceExists("BatUpload") )

{

EventLog.CreateEventSource("BatUpload",strMyLogName);

 

}

else

{

strMyLogName=EventLog.LogNameFromSourceName("BatUpload",".");

}

 

eventLog1.Source="BatUpload";

eventLog1.Log =strMyLogName;

eventLog1.WriteEntry(strFilesID,EventLogEntryType.Information);

 

}

}

 

}

 

MessageBox.Show(nCount.ToString());

 

}

catch(Exception ex)

{

MessageBox.Show(strFilesID +":" + ex.Message);

}

}

 

原创粉丝点击