BLOB,and storing duplicate documents to create document version system

  • Thread starter Thread starter vikas
  • Start date Start date
V

vikas

I am trying to create a document version management system using
ADO.net and SQL server.
I am storing the document in an Image field in the database.
I could sucessfully implement check in , check out, undo check out
functions but i am having one problem.
When i check out a document , make some changes to it and do check in
all previous versions of the document are also changes in such a way
that they also have the same document.

to chekin a document i first create a new database row..copy thw basic
infor from previous row..and then load the new document in the row..
please see the code below

//Get values from data row associated with the grid and make changes
in the master dataset table
private bool CheckInRow(DataRow dr, String sFile)
{
double fVersionNo ;
DataTable dt =null;
DataRow drNew = null;

fVersionNo = Convert.ToDouble(dr[m_strVersionCol].ToString());
dt = m_dsMaster.Tables[m_strTable];
drNew = dt.NewRow();
drNew[CUtil.GetColumn(m_strIDCol)] = new
TnrData.CUtil().GetTempID();
drNew[CUtil.GetColumn(m_strIDParentCol)] = dr[m_strIDParentCol];
drNew[CUtil.GetColumn(m_strShortCutCol)] = dr[m_strShortCutCol];
drNew[CUtil.GetColumn(m_strDocNameCol)] = dr[m_strDocNameCol];
drNew[CUtil.GetColumn(m_strDateRecievedCol)] = DateTime.Now;
drNew[CUtil.GetColumn(m_strAddedByCol)] = dr[m_strAddedByCol];
drNew[CUtil.GetColumn(m_strCommentCol)] = dr[m_strCommentCol];
drNew[CUtil.GetColumn(m_strIDDocTypeCol)] = dr[m_strIDDocTypeCol];
drNew[CUtil.GetColumn(m_strFileNameCol)] = dr[m_strFileNameCol];
drNew[CUtil.GetColumn(m_strSizeCol)] = CLGN.GetFileSize(sFile) /
1000;
drNew[CUtil.GetColumn(m_strLiveLinkCol)] = dr[m_strLiveLinkCol];
drNew[CUtil.GetColumn(m_strDocTypeCol)] = dr[m_strDocTypeCol];
drNew[CUtil.GetColumn(m_strCurrentCol)] = true;
drNew[CUtil.GetColumn(m_strCheckedOutCol)] = false;
drNew[CUtil.GetColumn(m_strVersionCol)] = fVersionNo + 1.0;
//CLGN.SetFileToRow(drNew, sFile,
CUtil.GetColumn(m_strDocImageCol));
try
{
//Create a temporary file for check in as SQL server needs to have
unique blob file

StringBuilder sb = new StringBuilder(sFile);
sb.Append("Tnr");sb.Append(drNew[CUtil.GetColumn(m_strVersionCol)].ToString());
sb.Append(".");sb.Append(drNew[CUtil.GetColumn(m_strDocTypeCol)].ToString());

String strCheckInFileName = sb.ToString();
//Make sure that file does not exist and then copy to create a
temporary file
File.Delete(strCheckInFileName);
File.Copy(sFile,strCheckInFileName);
FileStream fs = new
FileStream(strCheckInFileName,FileMode.Open,FileAccess.Read);
Byte[] bt = new Byte[(int)(fs.Length)];
fs.Read(bt, 0, (int)(fs.Length));
fs.Close();
drNew[CUtil.GetColumn(m_strDocImageCol)] = bt;
File.Delete(strCheckInFileName);
}
catch(System.IO.IOException ioe)
{
MessageBox.Show("Can Not Read File! \nThe Document File '" +
dr[m_strFileNameCol].ToString() +"' Does Not Exist In Checked Out
Folder Or Is Locked By Some Other Application.\n Please Close All
Aplications Using The File Before Checking In" , "",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}

dt.Rows.Add(drNew);
return true;

Could somebody please help and explain this behavior
Thanks,
Vikas
 
Hi vikas,

Can you show us insertcommand definition and how you handle database
updates?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

vikas said:
I am trying to create a document version management system using
ADO.net and SQL server.
I am storing the document in an Image field in the database.
I could sucessfully implement check in , check out, undo check out
functions but i am having one problem.
When i check out a document , make some changes to it and do check in
all previous versions of the document are also changes in such a way
that they also have the same document.

to chekin a document i first create a new database row..copy thw basic
infor from previous row..and then load the new document in the row..
please see the code below

//Get values from data row associated with the grid and make changes
in the master dataset table
private bool CheckInRow(DataRow dr, String sFile)
{
double fVersionNo ;
DataTable dt =null;
DataRow drNew = null;

fVersionNo = Convert.ToDouble(dr[m_strVersionCol].ToString());
dt = m_dsMaster.Tables[m_strTable];
drNew = dt.NewRow();
drNew[CUtil.GetColumn(m_strIDCol)] = new
TnrData.CUtil().GetTempID();
drNew[CUtil.GetColumn(m_strIDParentCol)] = dr[m_strIDParentCol];
drNew[CUtil.GetColumn(m_strShortCutCol)] = dr[m_strShortCutCol];
drNew[CUtil.GetColumn(m_strDocNameCol)] = dr[m_strDocNameCol];
drNew[CUtil.GetColumn(m_strDateRecievedCol)] = DateTime.Now;
drNew[CUtil.GetColumn(m_strAddedByCol)] = dr[m_strAddedByCol];
drNew[CUtil.GetColumn(m_strCommentCol)] = dr[m_strCommentCol];
drNew[CUtil.GetColumn(m_strIDDocTypeCol)] = dr[m_strIDDocTypeCol];
drNew[CUtil.GetColumn(m_strFileNameCol)] = dr[m_strFileNameCol];
drNew[CUtil.GetColumn(m_strSizeCol)] = CLGN.GetFileSize(sFile) /
1000;
drNew[CUtil.GetColumn(m_strLiveLinkCol)] = dr[m_strLiveLinkCol];
drNew[CUtil.GetColumn(m_strDocTypeCol)] = dr[m_strDocTypeCol];
drNew[CUtil.GetColumn(m_strCurrentCol)] = true;
drNew[CUtil.GetColumn(m_strCheckedOutCol)] = false;
drNew[CUtil.GetColumn(m_strVersionCol)] = fVersionNo + 1.0;
//CLGN.SetFileToRow(drNew, sFile,
CUtil.GetColumn(m_strDocImageCol));
try
{
//Create a temporary file for check in as SQL server needs to have
unique blob file

StringBuilder sb = new StringBuilder(sFile);
sb.Append("Tnr");sb.Append(drNew[CUtil.GetColumn(m_strVersionCol)].ToString(
));sb.Append(".");sb.Append(drNew[CUtil.GetColumn(m_strDocTypeCol)].ToString())
;

String strCheckInFileName = sb.ToString();
//Make sure that file does not exist and then copy to create a
temporary file
File.Delete(strCheckInFileName);
File.Copy(sFile,strCheckInFileName);
FileStream fs = new
FileStream(strCheckInFileName,FileMode.Open,FileAccess.Read);
Byte[] bt = new Byte[(int)(fs.Length)];
fs.Read(bt, 0, (int)(fs.Length));
fs.Close();
drNew[CUtil.GetColumn(m_strDocImageCol)] = bt;
File.Delete(strCheckInFileName);
}
catch(System.IO.IOException ioe)
{
MessageBox.Show("Can Not Read File! \nThe Document File '" +
dr[m_strFileNameCol].ToString() +"' Does Not Exist In Checked Out
Folder Or Is Locked By Some Other Application.\n Please Close All
Aplications Using The File Before Checking In" , "",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}

dt.Rows.Add(drNew);
return true;

Could somebody please help and explain this behavior
Thanks,
Vikas
 
I use commandbuilder to create the insert,update and delete command...
the select command of the commandbuilder is "select * from Table"
 
Hi vikas,

I suggest you to create adapters (and strong typed datasets) at design time.
In this way you'll see the code generated.
Does your table have primary key?
 
Hi Vikas,

In my opinion you make it more difficult for you than needed, I try first to
repeat what you want to do.
- Read a file from a database
- give the user the change to make changes
- check if the user did make changes and than add it in a new row in the
database.

So
Select the row using the select
Check if there are changes, just comparing the byteArray

When the byteArray is not equal to the previous create a new row with new
information what can be as

DataRow dr = dt.NewRow();
dr["blob"] = myblob;
dr["etcetc"] = rest
etc etc
ds.tables["mytable"].Rows.Add(dr);
da.Update(ds);

I hope this helps?

Cor
 
Back
Top