In Control Template Folder create a visual Webpart
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyDocsTreeView.ascx.cs" Inherits="MyDocsTreeView.ControlTemplates.MyDocsTreeView.MyDocsTreeView" %>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#IPFrame').on("load", function () {
var pageurl = window.location.href;
// alert(pageurl);
var pageurl = pageurl.substring(8, 14);
var MainSting = "FrameHeight";
var urlFrameHeight = MainSting.concat(pageurl);
$('#IPFrame').css('height', localStorage.getItem("" + urlFrameHeight + ""));
});
if ($('#<%= FolName.ClientID %>').text() != "")
{
var TreeNodeSession = "TreeNode";
if (sessionStorage.getItem("" + TreeNodeSession + "") != null) {
if (sessionStorage.getItem("" + TreeNodeSession + "").indexOf("CustomVDRView.aspx?RootFolder") >= 0) {
var iframePickturl = sessionStorage.getItem("" + TreeNodeSession + "").split('=/')[1];
$('#<%= lblProjectPath.ClientID %>').html("");
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath > ' + (iframePickturl.replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', sessionStorage.getItem("" + TreeNodeSession + ""));
}
else {
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + ((sessionStorage.getItem("" + TreeNodeSession + "")).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', sessionStorage.getItem("" + TreeNodeSession + ""));
}
}
else {
var defaultFrameUrlqueryString = $('#<%= FolName.ClientID %>').text();
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($('#<%= FolName.ClientID %>').text()).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', defaultFrameUrlqueryString);
}
}
else
{
var TreeNodeSession = "TreeNode";
if (sessionStorage.getItem("" + TreeNodeSession + "") != null)
{
if (sessionStorage.getItem("" + TreeNodeSession + "").indexOf("CustomVDRView.aspx?RootFolder") >= 0)
{
var iframePickturl = sessionStorage.getItem("" + TreeNodeSession + "").split('=/')[1];
$('#<%= lblProjectPath.ClientID %>').html("");
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath > ' + (iframePickturl.replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', sessionStorage.getItem("" + TreeNodeSession + ""));
}
else {
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + ((sessionStorage.getItem("" + TreeNodeSession + "")).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', sessionStorage.getItem("" + TreeNodeSession + ""));
}
}
else {
var defaultFrameUrl = $('#tvDocumentLibraryt0').attr('href');
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($('#tvDocumentLibraryt0').attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', defaultFrameUrl);
}
}
$('a').click(function (e) {
var linkID = $(this).attr("id");
//alert(linkID);
// alert($(this).attr('href'))
if (linkID == 'zz11_SiteActionsMenu')
{
// alert('Ram');
// e.preventDefault();
// e.stopPropagation();
}
else if (linkID == 'zz5_Menu')
{
// alert('Sita');
}
else if (linkID == 'ctl00_PlaceHolderLeftNavBar_idNavLinkRecycleBin')
{
// alert('Ram');
$("a").attr("target", "_blank");
}
else {
var imgSrcVal = $('img', this).attr("src");
if (imgSrcVal != undefined)
{
var n = imgSrcVal.indexOf("folder");
// alert(n);
if (n != -1)
{
// alert(imgSrcVal);
e.preventDefault();
// Start Only Used Set Of Hieght
var anchorText = $(this).text();
if (anchorText.indexOf("(") >= 0)
{
var splitext = anchorText.split('(')[1];
var finalsplitext = splitext.substring(0, splitext.length - 1);
var finallent = finalsplitext * 35;
$('#IPFrame').css('height', finallent + 200);
$('#s4-bodyContainer').css('height', finallent);
}
else {
//$('#IPFrame').css('height', 200);
//$('#s4-bodyContainer').css('height', 200);
}
//End Only Used Set Of Hieght
$('#<%= FolName.ClientID %>').text("");
sessionStorage.removeItem("" + TreeNodeSession + "");
sessionStorage.setItem("" + TreeNodeSession + "", $(this).attr('href'));
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($(this).attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', $(this).attr('href'));
//$("a").attr("target", "_blank");
}
else
{
var imgSrcVal = $('img', this).attr("src");
if (imgSrcVal.toLowerCase().indexOf('.jpg') >= 0 || imgSrcVal.toLowerCase().indexOf('.png') >= 0 || imgSrcVal.toLowerCase().indexOf('.gif') >= 0 )
{
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($(this).attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$("a").attr("target", "_blank");
}
else
{
//alert('Ram second');
$("a").attr("target", "_self");
e.stopPropagation();
}
}
}
else {
if (linkID != null && imgSrcVal == undefined)
{
if ($(this).attr('href').toLowerCase().indexOf('.pdf') >= 0 || $(this).attr('href').toLowerCase().indexOf('.png') >= 0 || $(this).attr('href').toLowerCase().indexOf('.jpg') >= 0 || $(this).attr('href').toLowerCase().indexOf('.txt') >= 0 || $(this).attr('href').toLowerCase().indexOf('.pptx') >= 0)
{
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($(this).attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$("a").attr("target", "_blank");
}
else
{
e.preventDefault();
// Start Only Used Set Of Hieght
var anchorText = $(this).text();
if (anchorText.indexOf("(") >= 0) {
var splitext = anchorText.split('(')[1];
var finalsplitext = splitext.substring(0, splitext.length - 1);
var finallent = finalsplitext * 35;
$('#IPFrame').css('height', finallent + 200);
$('#s4-bodyContainer').css('height', finallent);
}
else {
//$('#IPFrame').css('height', 200);
//$('#s4-bodyContainer').css('height', 200);
}
//End Only Used Set Of Hieght
sessionStorage.removeItem("" + TreeNodeSession + "");
sessionStorage.setItem("" + TreeNodeSession + "", $(this).attr('href'));
var roo = ($(this).attr('href')).replace(/\//g, ">");
$('#<%= FolName.ClientID %>').text("");
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($(this).attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', $(this).attr('href'));
}
}
}
}
});
});
</script>
<!--<div style="border-style: solid; border-width:1px">-->
<table>
<tr>
<td rowspan="2" valign="top">
<!--<div style="border:ridge;border-width:1px;margin-top:53px">-->
<div style="border-style: solid; border-width:1px;margin-top:2px">
<asp:TreeView ID="tvDocumentLibrary" runat="server" ClientIDMode="Static" EnableViewState="true" PopulateOnDemand="true" ExpandDepth="1" NodeStyle-HorizontalPadding="3" ShowExpandCollapse="true" ShowLines="true" Target="IPFrame" >
<SelectedNodeStyle ForeColor="Red" />
</asp:TreeView>
<div style="border-style: solid; border-width:0px">
<br />
<table border="0" cellpadding="0" cellspacing="0" class="ms-recyclebin1" width="100%">
<tbody>
<tr>
<td><a id="ctl00_PlaceHolderLeftNavBar_idNavLinkRecycleBin" href="/_layouts/recyclebin.aspx">
<img align="left" alt="" height="14px" src="/_layouts/images/recycbin.gif" style="border-width:0px;"> <span style="color:#339966;font-weight:bold; font-size: 12px;">Recycle Bin</span></img></a>
<br />
</td>
</tr>
</tbody>
</table>
</div>
<br />
</div>
</td>
</tr>
<tr >
<td valign="top" >
<div style="border-style: solid; border-width:1px">
<br />
<asp:Label ID="lblProjectPath" ClientIDMode="Static" runat="server"></asp:Label>
<br />
<br />
<iframe id="IPFrame" width="950px" style="min-height:100%; overflow:hidden; border:0" scrolling="no" >
</iframe>
</div>
</td>
</tr>
<asp:Label ID="FolName" ClientIDMode="Static" runat="server" style="display:none" Text=""></asp:Label>
</table>
****************** CS Page*********************************************
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.WebControls;
using System;
using System.Collections;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Services;
using System.IO;
namespace MyDocsTreeView.ControlTemplates.MyDocsTreeView
{
/*-------------------------------------------------------------------------------
File Name : MyDocsTreeView.cs
Function : it will show a tree View DocLIb with Indexing for VDR all project
Created By : Ram Vinay Singh
Created on : 12 Nov 2015
Revision History :
-------------------------------------------------------------------------------
*/
public partial class MyDocsTreeView : UserControl
{
ErrorLog objErrorLog = new ErrorLog();
string documentLibrary = string.Empty;
//string _strCurrentUser = string.Empty;
SPSite spSite = SPContext.Current.Site;
SPWeb spWeb;
string libName = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
libName = Page.Request.QueryString["fol"] != null ? Page.Request.QueryString["fol"] : string.Empty;
FolName.Text = libName;
// Retriving the document library name from the custom web part property //
tvDocumentLibrary.RootNodeStyle.BackColor = System.Drawing.Color.Transparent;
tvDocumentLibrary.NodeStyle.BackColor = System.Drawing.Color.Transparent;
tvDocumentLibrary.SelectedNodeStyle.BackColor = System.Drawing.Color.Transparent;
tvDocumentLibrary.SelectedNodeStyle.ForeColor = System.Drawing.Color.Red;
RetrieveDocLibName();
// Iterate through the root nodes in the Nodes property.
// ExpandNodes("PeguformVDRTest/Claims");
}
// Set the text to include children count.
for (int i = 0; i < tvDocumentLibrary.Nodes.Count; i++)
{
SetChildNodeText(tvDocumentLibrary.Nodes[i]);
}
}
[WebMethod]
public void RetrieveDocLibName()
{
try
{
MyDocsTreeViewMain.MyDocsTreeViewMain parent = (MyDocsTreeViewMain.MyDocsTreeViewMain)this.Parent;
documentLibrary = parent.ListName.ToString();
if (documentLibrary != null)
{
//lblprojectName.Text = "Project >" + documentLibrary;
// lblProjectPath.Text = documentLibrary;
SPSite site = SPContext.Current.Site;
spWeb = site.OpenWeb();
tvDocumentLibrary.Nodes.Clear();
// Creating an object of the document library //
//Commented on 29 oct 2015
SPDocumentLibrary spDocumentLibrary = (SPDocumentLibrary)spWeb.Lists[documentLibrary.Trim()];
// Creating an object of the root folder of the document library //
SPFolder spFolder = spDocumentLibrary.RootFolder;
// Creating the parent node of the tree view //
//Commented on 29 oct 2015
//TreeNode treeNodeRoot = new TreeNode(spFolder.Name.Trim(), spFolder.Name.Trim(), @"/_layouts/images/folder.gif", spFolder.ServerRelativeUrl.Trim(), "IPFrame");
TreeNode treeNodeRoot = new TreeNode(spFolder.Name.Trim(), spFolder.Name.Trim(), @"/_layouts/15/images/folder.gif", spFolder.ServerRelativeUrl.Trim(), "IPFrame");
// Calling the custom method to get all the folders //
GetAllFilesFolders(spFolder, treeNodeRoot);
// Adding the tree nodes to the tree view control //
tvDocumentLibrary.Nodes.Add(treeNodeRoot);
}
else
{
objErrorLog.WriteLog("Please mention a document library.");
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
/// <summary>
/// This custom menthod is used to get all the files and folders
/// </summary>
/// <param name="spFolder"></param>
/// <param name="parentNode"></param>
protected void GetAllFilesFolders(SPFolder spFolder, TreeNode parentNode)
{
SPQuery spQuery = new SPQuery();
spQuery.Query = @"<OrderBy><FieldRef Name='Created' Ascending='true' /></OrderBy>";
spQuery.Folder = spFolder;
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spWeb.Lists[spFolder.ParentListId].GetItems(spQuery);
foreach (SPListItem spListItem in spListItemCollection)
{
// Checking whether the item is a file or a folder //
if (spListItem.Folder != null)
{
// Creating the node for the folder //
//Commented on 29 oct 2015
TreeNode treeNodeChildFolder = new TreeNode(spListItem.Folder.Name.Trim(), Convert.ToString(spListItem.ID).Trim(), @"/_layouts/15/images/folder.gif", spListItem.Folder.ServerRelativeUrl.Trim(), "IPFrame");
// TreeNode treeNodeChildFolder = new TreeNode(spListItem.Folder.Name.Trim(), Convert.ToString(spListItem.ID).Trim(), @"/_layouts/images/folder.gif");
parentNode.ChildNodes.Add(treeNodeChildFolder);
// Calling the custom method to get all the subfolder and files within the folder //
GetAllFilesFolders(spListItem.Folder, treeNodeChildFolder);
}
else
{
// Creating and object of the file //
SPFile spFile = spListItem.File;
// Setting the display URL of the file //
string displayURL = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// Setting the icon URL of the file //
string iconURL = spFile.IconUrl.Trim();
int y = iconURL.LastIndexOf("/") + 1;
iconURL = @"/_layouts/15/images/" + iconURL.Substring(y, iconURL.Length - y);
// Creating the node of the file //
TreeNode treeNodeChildFile = new TreeNode(spFile.Name.Trim(), spFile.Name.Trim(), iconURL.Trim(), displayURL.Trim(), "IPFrame");
parentNode.ChildNodes.Add(treeNodeChildFile);
}
}
}
public void SetChildNodeText(TreeNode node)
{
if (node.ChildNodes.Count > 0)
{
// append child node count to the text
node.Text += " " + '(' + node.ChildNodes.Count.ToString() + ')';
}
for (int i = 0; i < node.ChildNodes.Count; i++)
{
// recursion
SetChildNodeText(node.ChildNodes[i]);
}
}
}
}
************************ and Create Web Part *******************************
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using Microsoft.SharePoint.WebPartPages;
namespace MyDocsTreeView.MyDocsTreeViewMain
{
[ToolboxItemAttribute(false)]
public class MyDocsTreeViewMain : Microsoft.SharePoint.WebPartPages.WebPart
{
private string docLibName = string.Empty;
public string ContactValue = null;
private const string _ascxPath = @"~/_CONTROLTEMPLATES/15/MyDocsTreeView/MyDocsTreeView/MyDocsTreeView.ascx";
/// <summary>
///
/// </summary>
///
public MyDocsTreeViewMain()
{
// retrieveAllIP();
// retrieveAllListLibrary();
}
protected override void CreateChildControls()
{
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
}
//DropDownList custom properties
public string ListName
{
get
{
return _listName;
}
set
{
_listName = value;
}
}
string _listName;
//public string ListValue
//{
// get
// {
// return _listValue;
// }
// set
// {
// _listValue = value;
// }
//}
//string _listValue;
public override ToolPart[] GetToolParts()
{
ToolPart[] allToolParts = new ToolPart[3];
WebPartToolPart standardToolParts = new WebPartToolPart();
CustomPropertyToolPart customToolParts = new CustomPropertyToolPart();
allToolParts[0] = standardToolParts;
allToolParts[1] = customToolParts;
allToolParts[2] = new VDRCustomToolPart();
return allToolParts;
}
}
}
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyDocsTreeView.ascx.cs" Inherits="MyDocsTreeView.ControlTemplates.MyDocsTreeView.MyDocsTreeView" %>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#IPFrame').on("load", function () {
var pageurl = window.location.href;
// alert(pageurl);
var pageurl = pageurl.substring(8, 14);
var MainSting = "FrameHeight";
var urlFrameHeight = MainSting.concat(pageurl);
$('#IPFrame').css('height', localStorage.getItem("" + urlFrameHeight + ""));
});
if ($('#<%= FolName.ClientID %>').text() != "")
{
var TreeNodeSession = "TreeNode";
if (sessionStorage.getItem("" + TreeNodeSession + "") != null) {
if (sessionStorage.getItem("" + TreeNodeSession + "").indexOf("CustomVDRView.aspx?RootFolder") >= 0) {
var iframePickturl = sessionStorage.getItem("" + TreeNodeSession + "").split('=/')[1];
$('#<%= lblProjectPath.ClientID %>').html("");
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath > ' + (iframePickturl.replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', sessionStorage.getItem("" + TreeNodeSession + ""));
}
else {
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + ((sessionStorage.getItem("" + TreeNodeSession + "")).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', sessionStorage.getItem("" + TreeNodeSession + ""));
}
}
else {
var defaultFrameUrlqueryString = $('#<%= FolName.ClientID %>').text();
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($('#<%= FolName.ClientID %>').text()).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', defaultFrameUrlqueryString);
}
}
else
{
var TreeNodeSession = "TreeNode";
if (sessionStorage.getItem("" + TreeNodeSession + "") != null)
{
if (sessionStorage.getItem("" + TreeNodeSession + "").indexOf("CustomVDRView.aspx?RootFolder") >= 0)
{
var iframePickturl = sessionStorage.getItem("" + TreeNodeSession + "").split('=/')[1];
$('#<%= lblProjectPath.ClientID %>').html("");
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath > ' + (iframePickturl.replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', sessionStorage.getItem("" + TreeNodeSession + ""));
}
else {
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + ((sessionStorage.getItem("" + TreeNodeSession + "")).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', sessionStorage.getItem("" + TreeNodeSession + ""));
}
}
else {
var defaultFrameUrl = $('#tvDocumentLibraryt0').attr('href');
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($('#tvDocumentLibraryt0').attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', defaultFrameUrl);
}
}
$('a').click(function (e) {
var linkID = $(this).attr("id");
//alert(linkID);
// alert($(this).attr('href'))
if (linkID == 'zz11_SiteActionsMenu')
{
// alert('Ram');
// e.preventDefault();
// e.stopPropagation();
}
else if (linkID == 'zz5_Menu')
{
// alert('Sita');
}
else if (linkID == 'ctl00_PlaceHolderLeftNavBar_idNavLinkRecycleBin')
{
// alert('Ram');
$("a").attr("target", "_blank");
}
else {
var imgSrcVal = $('img', this).attr("src");
if (imgSrcVal != undefined)
{
var n = imgSrcVal.indexOf("folder");
// alert(n);
if (n != -1)
{
// alert(imgSrcVal);
e.preventDefault();
// Start Only Used Set Of Hieght
var anchorText = $(this).text();
if (anchorText.indexOf("(") >= 0)
{
var splitext = anchorText.split('(')[1];
var finalsplitext = splitext.substring(0, splitext.length - 1);
var finallent = finalsplitext * 35;
$('#IPFrame').css('height', finallent + 200);
$('#s4-bodyContainer').css('height', finallent);
}
else {
//$('#IPFrame').css('height', 200);
//$('#s4-bodyContainer').css('height', 200);
}
//End Only Used Set Of Hieght
$('#<%= FolName.ClientID %>').text("");
sessionStorage.removeItem("" + TreeNodeSession + "");
sessionStorage.setItem("" + TreeNodeSession + "", $(this).attr('href'));
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($(this).attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', $(this).attr('href'));
//$("a").attr("target", "_blank");
}
else
{
var imgSrcVal = $('img', this).attr("src");
if (imgSrcVal.toLowerCase().indexOf('.jpg') >= 0 || imgSrcVal.toLowerCase().indexOf('.png') >= 0 || imgSrcVal.toLowerCase().indexOf('.gif') >= 0 )
{
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($(this).attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$("a").attr("target", "_blank");
}
else
{
//alert('Ram second');
$("a").attr("target", "_self");
e.stopPropagation();
}
}
}
else {
if (linkID != null && imgSrcVal == undefined)
{
if ($(this).attr('href').toLowerCase().indexOf('.pdf') >= 0 || $(this).attr('href').toLowerCase().indexOf('.png') >= 0 || $(this).attr('href').toLowerCase().indexOf('.jpg') >= 0 || $(this).attr('href').toLowerCase().indexOf('.txt') >= 0 || $(this).attr('href').toLowerCase().indexOf('.pptx') >= 0)
{
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($(this).attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$("a").attr("target", "_blank");
}
else
{
e.preventDefault();
// Start Only Used Set Of Hieght
var anchorText = $(this).text();
if (anchorText.indexOf("(") >= 0) {
var splitext = anchorText.split('(')[1];
var finalsplitext = splitext.substring(0, splitext.length - 1);
var finallent = finalsplitext * 35;
$('#IPFrame').css('height', finallent + 200);
$('#s4-bodyContainer').css('height', finallent);
}
else {
//$('#IPFrame').css('height', 200);
//$('#s4-bodyContainer').css('height', 200);
}
//End Only Used Set Of Hieght
sessionStorage.removeItem("" + TreeNodeSession + "");
sessionStorage.setItem("" + TreeNodeSession + "", $(this).attr('href'));
var roo = ($(this).attr('href')).replace(/\//g, ">");
$('#<%= FolName.ClientID %>').text("");
$('#<%= lblProjectPath.ClientID %>').html('VDRRootpath ' + (($(this).attr('href')).replace(/\//g, ">")).replace(/%20/g, " "));
$('#IPFrame').attr('src', $(this).attr('href'));
}
}
}
}
});
});
</script>
<!--<div style="border-style: solid; border-width:1px">-->
<table>
<tr>
<td rowspan="2" valign="top">
<!--<div style="border:ridge;border-width:1px;margin-top:53px">-->
<div style="border-style: solid; border-width:1px;margin-top:2px">
<asp:TreeView ID="tvDocumentLibrary" runat="server" ClientIDMode="Static" EnableViewState="true" PopulateOnDemand="true" ExpandDepth="1" NodeStyle-HorizontalPadding="3" ShowExpandCollapse="true" ShowLines="true" Target="IPFrame" >
<SelectedNodeStyle ForeColor="Red" />
</asp:TreeView>
<div style="border-style: solid; border-width:0px">
<br />
<table border="0" cellpadding="0" cellspacing="0" class="ms-recyclebin1" width="100%">
<tbody>
<tr>
<td><a id="ctl00_PlaceHolderLeftNavBar_idNavLinkRecycleBin" href="/_layouts/recyclebin.aspx">
<img align="left" alt="" height="14px" src="/_layouts/images/recycbin.gif" style="border-width:0px;"> <span style="color:#339966;font-weight:bold; font-size: 12px;">Recycle Bin</span></img></a>
<br />
</td>
</tr>
</tbody>
</table>
</div>
<br />
</div>
</td>
</tr>
<tr >
<td valign="top" >
<div style="border-style: solid; border-width:1px">
<br />
<asp:Label ID="lblProjectPath" ClientIDMode="Static" runat="server"></asp:Label>
<br />
<br />
<iframe id="IPFrame" width="950px" style="min-height:100%; overflow:hidden; border:0" scrolling="no" >
</iframe>
</div>
</td>
</tr>
<asp:Label ID="FolName" ClientIDMode="Static" runat="server" style="display:none" Text=""></asp:Label>
</table>
****************** CS Page*********************************************
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.WebControls;
using System;
using System.Collections;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Services;
using System.IO;
namespace MyDocsTreeView.ControlTemplates.MyDocsTreeView
{
/*-------------------------------------------------------------------------------
File Name : MyDocsTreeView.cs
Function : it will show a tree View DocLIb with Indexing for VDR all project
Created By : Ram Vinay Singh
Created on : 12 Nov 2015
Revision History :
-------------------------------------------------------------------------------
*/
public partial class MyDocsTreeView : UserControl
{
ErrorLog objErrorLog = new ErrorLog();
string documentLibrary = string.Empty;
//string _strCurrentUser = string.Empty;
SPSite spSite = SPContext.Current.Site;
SPWeb spWeb;
string libName = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
libName = Page.Request.QueryString["fol"] != null ? Page.Request.QueryString["fol"] : string.Empty;
FolName.Text = libName;
// Retriving the document library name from the custom web part property //
tvDocumentLibrary.RootNodeStyle.BackColor = System.Drawing.Color.Transparent;
tvDocumentLibrary.NodeStyle.BackColor = System.Drawing.Color.Transparent;
tvDocumentLibrary.SelectedNodeStyle.BackColor = System.Drawing.Color.Transparent;
tvDocumentLibrary.SelectedNodeStyle.ForeColor = System.Drawing.Color.Red;
RetrieveDocLibName();
// Iterate through the root nodes in the Nodes property.
// ExpandNodes("PeguformVDRTest/Claims");
}
// Set the text to include children count.
for (int i = 0; i < tvDocumentLibrary.Nodes.Count; i++)
{
SetChildNodeText(tvDocumentLibrary.Nodes[i]);
}
}
[WebMethod]
public void RetrieveDocLibName()
{
try
{
MyDocsTreeViewMain.MyDocsTreeViewMain parent = (MyDocsTreeViewMain.MyDocsTreeViewMain)this.Parent;
documentLibrary = parent.ListName.ToString();
if (documentLibrary != null)
{
//lblprojectName.Text = "Project >" + documentLibrary;
// lblProjectPath.Text = documentLibrary;
SPSite site = SPContext.Current.Site;
spWeb = site.OpenWeb();
tvDocumentLibrary.Nodes.Clear();
// Creating an object of the document library //
//Commented on 29 oct 2015
SPDocumentLibrary spDocumentLibrary = (SPDocumentLibrary)spWeb.Lists[documentLibrary.Trim()];
// Creating an object of the root folder of the document library //
SPFolder spFolder = spDocumentLibrary.RootFolder;
// Creating the parent node of the tree view //
//Commented on 29 oct 2015
//TreeNode treeNodeRoot = new TreeNode(spFolder.Name.Trim(), spFolder.Name.Trim(), @"/_layouts/images/folder.gif", spFolder.ServerRelativeUrl.Trim(), "IPFrame");
TreeNode treeNodeRoot = new TreeNode(spFolder.Name.Trim(), spFolder.Name.Trim(), @"/_layouts/15/images/folder.gif", spFolder.ServerRelativeUrl.Trim(), "IPFrame");
// Calling the custom method to get all the folders //
GetAllFilesFolders(spFolder, treeNodeRoot);
// Adding the tree nodes to the tree view control //
tvDocumentLibrary.Nodes.Add(treeNodeRoot);
}
else
{
objErrorLog.WriteLog("Please mention a document library.");
}
}
catch (Exception ex)
{
objErrorLog.WriteLog(ex.ToString());
}
}
/// <summary>
/// This custom menthod is used to get all the files and folders
/// </summary>
/// <param name="spFolder"></param>
/// <param name="parentNode"></param>
protected void GetAllFilesFolders(SPFolder spFolder, TreeNode parentNode)
{
SPQuery spQuery = new SPQuery();
spQuery.Query = @"<OrderBy><FieldRef Name='Created' Ascending='true' /></OrderBy>";
spQuery.Folder = spFolder;
string strCurrentUserName = spWeb.CurrentUser.Name.ToString();
SPListItemCollection spListItemCollection = spWeb.Lists[spFolder.ParentListId].GetItems(spQuery);
foreach (SPListItem spListItem in spListItemCollection)
{
// Checking whether the item is a file or a folder //
if (spListItem.Folder != null)
{
// Creating the node for the folder //
//Commented on 29 oct 2015
TreeNode treeNodeChildFolder = new TreeNode(spListItem.Folder.Name.Trim(), Convert.ToString(spListItem.ID).Trim(), @"/_layouts/15/images/folder.gif", spListItem.Folder.ServerRelativeUrl.Trim(), "IPFrame");
// TreeNode treeNodeChildFolder = new TreeNode(spListItem.Folder.Name.Trim(), Convert.ToString(spListItem.ID).Trim(), @"/_layouts/images/folder.gif");
parentNode.ChildNodes.Add(treeNodeChildFolder);
// Calling the custom method to get all the subfolder and files within the folder //
GetAllFilesFolders(spListItem.Folder, treeNodeChildFolder);
}
else
{
// Creating and object of the file //
SPFile spFile = spListItem.File;
// Setting the display URL of the file //
string displayURL = spWeb.Url.Trim() + @"/" + spFile.Url.Trim();
// Setting the icon URL of the file //
string iconURL = spFile.IconUrl.Trim();
int y = iconURL.LastIndexOf("/") + 1;
iconURL = @"/_layouts/15/images/" + iconURL.Substring(y, iconURL.Length - y);
// Creating the node of the file //
TreeNode treeNodeChildFile = new TreeNode(spFile.Name.Trim(), spFile.Name.Trim(), iconURL.Trim(), displayURL.Trim(), "IPFrame");
parentNode.ChildNodes.Add(treeNodeChildFile);
}
}
}
public void SetChildNodeText(TreeNode node)
{
if (node.ChildNodes.Count > 0)
{
// append child node count to the text
node.Text += " " + '(' + node.ChildNodes.Count.ToString() + ')';
}
for (int i = 0; i < node.ChildNodes.Count; i++)
{
// recursion
SetChildNodeText(node.ChildNodes[i]);
}
}
}
}
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using Microsoft.SharePoint.WebPartPages;
namespace MyDocsTreeView.MyDocsTreeViewMain
{
[ToolboxItemAttribute(false)]
public class MyDocsTreeViewMain : Microsoft.SharePoint.WebPartPages.WebPart
{
private string docLibName = string.Empty;
public string ContactValue = null;
private const string _ascxPath = @"~/_CONTROLTEMPLATES/15/MyDocsTreeView/MyDocsTreeView/MyDocsTreeView.ascx";
/// <summary>
///
/// </summary>
///
public MyDocsTreeViewMain()
{
// retrieveAllIP();
// retrieveAllListLibrary();
}
protected override void CreateChildControls()
{
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
}
//DropDownList custom properties
public string ListName
{
get
{
return _listName;
}
set
{
_listName = value;
}
}
string _listName;
//public string ListValue
//{
// get
// {
// return _listValue;
// }
// set
// {
// _listValue = value;
// }
//}
//string _listValue;
public override ToolPart[] GetToolParts()
{
ToolPart[] allToolParts = new ToolPart[3];
WebPartToolPart standardToolParts = new WebPartToolPart();
CustomPropertyToolPart customToolParts = new CustomPropertyToolPart();
allToolParts[0] = standardToolParts;
allToolParts[1] = customToolParts;
allToolParts[2] = new VDRCustomToolPart();
return allToolParts;
}
}
}
****************************** Error Class **********************
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Configuration;
namespace MyDocsTreeView
{
public class ErrorLog
{
public void WriteLog(string strLog)
{
System.IO.StreamWriter log;
FileStream fileStream = null;
DirectoryInfo logDirInfo = null;
FileInfo logFileInfo;
//string Folderpath = WebConfigurationManager.AppSettings["ErrorFolderpath"].ToString();
string logFilePath = "C:\\Logs\\";
// string logFilePath = Folderpath;
logFilePath = logFilePath + "VDR" + System.DateTime.Today.ToString("dd-MM-yyyy") + "." + "txt";
logFileInfo = new FileInfo(logFilePath);
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
if (!logDirInfo.Exists) logDirInfo.Create();
if (!logFileInfo.Exists)
{
fileStream = logFileInfo.Create();
}
else
{
fileStream = new FileStream(logFilePath, FileMode.Append);
}
log = new StreamWriter(fileStream);
log.WriteLine("*******************************" + DateTime.Now + "********************************");
log.WriteLine(strLog);
log.Close();
}
}
}
No comments:
Post a Comment