private void _PreviewAttachmentList_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { try { if (e.Button == MouseButtons.Right) { TreeNode oNode = _PreviewAttachmentList.GetNodeAt(e.X, e.Y); if (oNode != null) { _SelectedPreviewFile = (AttachmentListItem) oNode; _PreviewAttachmentListContextMenu.Show(_PreviewAttachmentList, new Point(e.X, e.Y)); } } } catch (Exception ex) { MessageBox.Show(this, ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// This method loads a listitem attachments. /// /// In case of a document library, the nature of the list (contains files by itself), /// this list will always contain a single attachment file. /// </summary> /// <param name="spList"></param> /// <param name="spItemID"></param> private void LoadPreviewAttachmentList(SP.SPListDefinition spList, int spItemID) { _PreviewAttachmentList.Nodes.Clear(); if (spList == null || spItemID == 0) return; // extract the attachments linked to the currently selected list item. DataTable oFilesTable = _ExecContext.SPDatabase.GetListItemAttachmentsList(spList, spItemID, false); if (oFilesTable != null) { // add an item in the treeview for each attachment. foreach (DataRow oFileRow in oFilesTable.Rows) { string sFilename = oFileRow["Filename"].ToString(); string sText = sFilename; string sAttachmentID = oFileRow["DocID"].ToString(); if (!oFileRow.IsNull("CheckoutDate")) sText = string.Format("{0} ===> a pending version is available (expand to see)", sFilename); AttachmentListItem oAttachmentNode = new AttachmentListItem(sText, sFilename, spItemID, spList, sAttachmentID); _PreviewAttachmentList.Nodes.Add(oAttachmentNode); //if the file is currently checked out, we display the information //next to the filename. if (!oFileRow.IsNull("CheckoutDate")) { sText = string.Format("pending version checked-out on: {0:yyyy/MM/dd hh:mm}", oFileRow["CheckoutDate"]); AttachmentListItem oHistoryNode = new AttachmentListItem(sText, sFilename, spItemID, spList, sAttachmentID, AttachmentListItem.CHECKED_OUT_VERSION); oAttachmentNode.Nodes.Add(oHistoryNode); } // extract the previous versions of the attachment (if any). DataTable oHistory = _ExecContext.SPDatabase.GetAttachmentHistoryList(spList, sAttachmentID); foreach (DataRow oHistoryRow in oHistory.Rows) { sText = string.Format("v.{0} ({1:yyyy-MM-dd HH:mm:ss})", oHistoryRow["VersionNumber"], oHistoryRow["TimeCreated"]); string sHistoryFilename = string.Format("{0}-v{1}{2}", System.IO.Path.GetFileNameWithoutExtension(sFilename), oHistoryRow["VersionNumber"], System.IO.Path.GetExtension(sFilename)); AttachmentListItem oHistoryNode = new AttachmentListItem(sText, sHistoryFilename, spItemID, spList, sAttachmentID, Convert.ToInt32(oHistoryRow["VersionNumber"])); oAttachmentNode.Nodes.Add(oHistoryNode); } } } }