This is a migrated thread and some comments may be shown as answers.

How to refresh treeview section in radfileexplorer after create/delete/rename folder..?

3 Answers 123 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Praveen
Top achievements
Rank 1
Praveen asked on 14 Nov 2011, 06:25 AM
Hi,

I am using telerik 35 version dll . The treeview section in radfileexplorer not refreshing after create/delete/rename folder functionalities.
The refreshment happening only in grid section.

Please help me with exact code..and event..

Regards,

Praveen.

3 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 17 Nov 2011, 10:45 AM
Hi Praveen,

Unfortunately, the provided information is not enough to determine the exact cause of the problem. Could you please provide more detailed information on the specific scenario.
  • Which version of RadControls for ASP.NET AJAX is used in the application?
  • Under which browser and its version the problem occurs?
  • Are you able to reproduce the problem on the live demos? If so, could you please provide the exact steps the need to be executed in order to reproduce the issue?
  • Are there any JavaScript errors thrown on the page during execution of the mentioned operations and / or during page load? If so, could you please provide the exact error message?
  • Have you applied any customizations to RadFileExplorer - client-side event handlers, server-side event handlers, custom content provider? If so could you try to disable them and see if the problem still occurs?
  • Could you please provide a simple fully runnable project reproducing the problem so we can investigate it further?

Looking forward to hearing from you,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Praveen
Top achievements
Rank 1
answered on 18 Nov 2011, 06:53 AM
Hi,
I am using  Telerik version 35 dll.

I am here with putting the provider class and fileexplorer page.
Verify these and reply me immediatly..

Regards,
Praveen.


using

 

 

System;

 

using

 

 

System.Data;

 

using

 

 

System.IO;

 

using

 

 

System.Configuration;

 

using

 

 

System.Web;

 

using

 

 

System.Web.Security;

 

using

 

 

System.Web.UI;

 

using

 

 

System.Web.UI.WebControls;

 

using

 

 

System.Web.UI.WebControls.WebParts;

 

using

 

 

System.Web.UI.HtmlControls;

 

using

 

 

Telerik.Web.UI.Widgets;

 

using

 

 

System.Collections.Generic;

 

using

 

 

System.Collections;

 

using

 

 

LegalBusinessInterface;

 

using

 

 

LegalDomain;

 

using

 

 

LegalDal;

 

using

 

 

System.Text;

 

using

 

 

System.Linq;

 

using

 

 

Microsoft.WindowsAzure.StorageClient;

 

using

 

 

Microsoft.WindowsAzure.Diagnostics;

 

using

 

 

Microsoft.WindowsAzure;

 

using

 

 

System.Drawing;

 

using

 

 

System.Web.Security;

 

using

 

 

System.Web;

 

namespace

 

 

LegalBusiness

 

{

 

 

public partial class DBContentProvider : Telerik.Web.UI.Widgets.FileSystemContentProvider

 

{

#region

 

 

declarations

 

 

 

private DataServer _dataServer;

 

 

 

private DataServer DataServer

 

{

 

 

get

 

{

 

 

if (Object.Equals(_dataServer, null))

 

{

_dataServer =

 

new DataServer(CloudStorageAccount.DevelopmentStorageAccount);

 

}

 

 

return _dataServer;

 

}

}

 

 

private string _itemHandlerPath;

 

 

 

private string ItemHandlerPath

 

{

 

 

get

 

{

 

 

return _itemHandlerPath;

 

}

}

 

 

private string[] RestrictUpload = { ".msi", ".bin", ".jar", ".jsx", ".vbs", ".js", ".htm", ".html", ".shtml", ".phtml", ".sh", ".pl", ".py", ".cgi", ".exe", ".dll", ".bin", ".jar", ".jsx" };

 

#endregion

 

 

 

public string BlobUri

 

{

 

 

get;

 

 

 

set;

 

}

 

 

public DBContentProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)

 

:

 

 

base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)

 

{

_itemHandlerPath =

 

ConfigurationManager.AppSettings["Telerik.WebControls.EditorExamples.ItemHandler"];

 

 

 

if (_itemHandlerPath.StartsWith("~/"))

 

{

 

 

//_itemHandlerPath = HttpContext.Current.Request.ApplicationPath + _itemHandlerPath.Substring(1);

 

_itemHandlerPath =

 

HttpContext.Current.Request.Url.AbsoluteUri.ToString().Replace(HttpContext.Current.Request.RawUrl, "") + _itemHandlerPath.Substring(1);

 

}

 

 

if (SelectedItemTag != null && SelectedItemTag != string.Empty)

 

{

SelectedItemTag = ExtractPath(RemoveProtocolNameAndServerName(SelectedItemTag));

}

}

 

 

 

public override string CreateDirectory(string path, string name)

 

{

 

DataServer.CreateItem(name, path);

 

 

return string.Empty;

 

 

}

 

 

public override string DeleteDirectory(string path)

 

{

 

 

string folderpath = GetPath(path);

 

 

 

string folderid = DataServer.GetFolderId(path);

 

DataServer.DeleteDirectory(folderid);

 

 

return string.Empty;

 

}

 

 

public override string MoveDirectory(string path, string newPath)

 

{

 

 

string folderpath = GetPath(path);

 

 

 

string folderid = DataServer.GetFolderId(path);

 

 

 

int index = newPath.LastIndexOf("/");

 

 

 

string newName = newPath.Substring(index + 1);

 

 

 

//---------Rename a file in radfile explorer-----------

 

DataServer.RenameFolder(folderid, newName);

 

 

return string.Empty;

 

}

 

 

/// <summary>

 

 

 

/// delete file from rad file explorer

 

 

 

/// </summary>

 

 

 

/// <param name="path"></param>

 

 

 

/// <returns></returns>

 

 

 

public override string DeleteFile(string path)

 

{

 

 

try

 

{

DataServer.DeleteFile(path);

 

 

return string.Empty;

 

}

 

 

catch (Exception ex)

 

{

 

 

throw ex;

 

}

}

 

 

public override Stream GetFile(string url)

 

{

 

 

byte[] content = DataServer.GetContent(ExtractPath(RemoveProtocolNameAndServerName(url)));

 

 

 

if (!Object.Equals(content, null))

 

{

 

 

return new MemoryStream(content);

 

}

 

 

return null;

 

}

 

 

/// <summary>

 

 

 

/// method to move/rename file

 

 

 

/// </summary>

 

 

 

/// <param name="path"></param>

 

 

 

/// <param name="newpath"></param>

 

 

 

/// <returns></returns>

 

 

 

public override string MoveFile(string path,string newpath)

 

{

 

 

 

int index = path.LastIndexOf("/");

 

 

 

string filename1 = path.Substring(index+1);

 

index = newpath.LastIndexOf(

 

"/");

 

 

 

string filename2 = newpath.Substring(index + 1);

 

 

 

if (filename1 != filename2)

 

{

 

 

//---------Rename a file in radfile explorer-----------

 

DataServer.RenameFile(path, newpath);

}

 

 

else

 

{

 

 

//---------Move functionality is done here-----------

 

 

 

string folderpath = GetPath(newpath);

 

 

 

string folderid = DataServer.GetFolderId(folderpath);

 

DataServer.MoveFile(path, folderid);

}

 

 

return string.Empty;

 

}

 

 

 

public override string GetFileName(string url)

 

{

 

 

throw new NotImplementedException();

 

}

 

 

public override string GetPath(string url)

 

{

 

 

return GetDirectoryPath(ExtractPath(RemoveProtocolNameAndServerName(url)));

 

}

 

 

public override DirectoryItem ResolveDirectory(string path)

 

{

 

 

DirectoryItem[] directories = GetChildDirectories(path);

 

 

 

DirectoryItem returnValue = new DirectoryItem(GetName(path),

 

 

 

VirtualPathUtility.AppendTrailingSlash(GetDirectoryPath(path)),

 

path,

 

 

string.Empty,

 

GetPermissions(path),

GetChildFiles(path),

 

 

null // Directories are added in ResolveRootDirectoryAsTree()

 

);

 

 

return returnValue;

 

}

 

 

public override DirectoryItem ResolveRootDirectoryAsTree(string path)

 

{

 

 

DirectoryItem returnValue = new DirectoryItem(GetName(path),

 

GetDirectoryPath(path),

path,

 

 

string.Empty,

 

GetPermissions(path),

 

 

null, // The files are added in ResolveDirectory()

 

GetChildDirectories(path));

 

 

 

return returnValue;

 

}

 

 

public override string StoreBitmap(System.Drawing.Bitmap bitmap, string url, System.Drawing.Imaging.ImageFormat format)

 

{

 

 

throw new NotImplementedException();

 

}

 

 

public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)

 

{

 

 

string ReadyToUpload = "Yes";

 

 

 

string Extension = "";

 

Extension= file.GetExtension();

 

 

for (int count = 0; count < RestrictUpload.Length; count++)

 

{

 

 

if (Extension == RestrictUpload[count])

 

ReadyToUpload =

 

"No";

 

}

 

 

if (ReadyToUpload == "Yes")

 

{

 

 

cmsBusiness ocmsBusiness = new cmsBusiness();

 

 

 

int fileLength = Convert.ToInt32(file.InputStream.Length);

 

 

 

byte[] content = new byte[fileLength];

 

file.InputStream.Read(content, 0, fileLength);

 

 

string fullPath = CombinePath(path, name);

 

 

 

Stream oStream = new MemoryStream(content);

 

 

 

//--------------Commented for refreshing------------

 

 

 

//if (!Object.Equals(DataServer.GetBlobContentRow(fullPath), null))

 

 

 

//{

 

 

 

// // DataServer.ReplaceItemContent(fullPath, content);

 

 

 

//}

 

 

 

//else

 

 

 

//{

 

 

 

CmsFolderContentBlob ofolderContent = new CmsFolderContentBlob();

 

 

 

string _blobName = Guid.NewGuid() + "_" + name;

 

 

 

int bufferSize = 40 * 1024; // 40 KB.

 

 

 

byte[] bufferBytes = new byte[4096000];

 

 

 

string fileName = name;//Guid.NewGuid().ToString() + "$" + "cmsblobcontent";

 

 

 

string uri = "";

 

 

 

int blockCount = (int)(oStream.Length / bufferSize) + 1;

 

 

 

List<string> blockIds = new List<string>();

 

 

 

for (int i = 0; i < blockCount; i++)

 

{

oStream.Read(bufferBytes, 0, bufferSize);

 

 

string currentBlockId = Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));

 

blockIds.Add(currentBlockId);

ofolderContent.FileName = fileName;

ofolderContent.currentBlockId = currentBlockId;

ofolderContent.base64Content =

 

Convert.ToBase64String(bufferBytes);

 

uri = DataServer.PutBlockforRad(ofolderContent);

}

ofolderContent.blockIds = blockIds;

 

 

string caseId = "";

 

 

 

string userName = "";

 

 

 

if (HttpContext.Current.Session["case"] != null)

 

{

caseId =

 

HttpContext.Current.Session["case"].ToString();

 

}

 

 

if (HttpContext.Current.Session["UserName"] != null)

 

{

userName =

 

HttpContext.Current.Session["UserName"].ToString();

 

}

 

 

string uriBlock = (DataServer.PutBlockListforRad(ofolderContent.blockIds, ofolderContent.FileName));

 

DataServer.InsertBlobFile(path, uriBlock, content.LongLength, userName, caseId);

 

 

// }

 

}

 

 

else

 

{

 

 

return "NoUpload";

 

}

 

 

return string.Empty;

 

 

}

#region

 

 

private methods

 

 

 

private string ExtractPath(string itemUrl)

 

{

 

 

if (itemUrl == null)

 

{

 

 

return string.Empty;

 

}

 

 

if (itemUrl.StartsWith(_itemHandlerPath))

 

{

 

 

return itemUrl.Substring(GetItemUrl(string.Empty).Length);

 

}

 

 

return itemUrl;

 

}

 

 

private string GetItemUrl(string virtualItemPath)

 

{

 

 

return string.Format("{0}?BlobUri={1}", ItemHandlerPath, virtualItemPath);

 

 

}

 

 

private string GetName(string path)

 

{

 

 

if (String.IsNullOrEmpty(path) || path == "/")

 

{

 

 

return string.Empty;

 

}

path =

 

VirtualPathUtility.RemoveTrailingSlash(path);

 

 

 

return path.Substring(path.LastIndexOf('/') + 1);

 

}

 

 

private string GetDirectoryPath(string path)

 

{

 

 

return path.Substring(0, path.LastIndexOf('/') + 1);

 

}

 

 

/// <summary>

 

 

 

/// Checks Upload permissions

 

 

 

/// </summary>

 

 

 

/// <param name="path">Path to an item</param>

 

 

 

/// <returns></returns>

 

 

 

private bool HasUploadPermission(string path)

 

{

 

 

foreach (string uploadPath in this.UploadPaths)

 

{

 

 

if (path.StartsWith(uploadPath, StringComparison.CurrentCultureIgnoreCase))

 

{

 

 

return true;

 

}

}

 

 

return false;

 

}

 

 

/// <summary>

 

 

 

/// Checks Delete permissions

 

 

 

/// </summary>

 

 

 

/// <param name="path">Path to an item</param>

 

 

 

/// <returns></returns>

 

 

 

private bool HasDeletePermission(string path)

 

{

 

 

foreach (string deletePath in this.DeletePaths)

 

{

 

 

if (path.StartsWith(deletePath, StringComparison.CurrentCultureIgnoreCase))

 

{

 

 

return true;

 

}

}

 

 

return false;

 

}

//*****************************************************************************************************************

 

 

/// <summary>

 

 

 

/// permission to delete a file from rad file explorer

 

 

 

/// </summary>

 

 

 

/// <param name="folderPath"></param>

 

 

 

/// <returns></returns>

 

 

 

public override bool CheckDeletePermissions(string folderPath)

 

{

 

 

return true;

 

}

 

 

public override bool CheckWritePermissions(string folderPath)

 

{

 

 

return true;

 

}

 

 

public override bool CheckReadPermissions(string folderPath)

 

{

 

 

return true;

 

}

//******************************************************************************************************************

 

 

/// <summary>

 

 

 

/// Returns the permissions for the provided path

 

 

 

/// </summary>

 

 

 

/// <param name="pathToItem">Path to an item</param>

 

 

 

/// <returns></returns>

 

 

 

private PathPermissions GetPermissions(string pathToItem)

 

{

 

 

PathPermissions permission = PathPermissions.Read;

 

permission = HasUploadPermission(pathToItem) ? permission |

 

PathPermissions.Upload : permission;

 

permission = HasDeletePermission(pathToItem) ? permission |

 

PathPermissions.Delete : permission;

 

 

 

return permission;

 

}

 

 

/// <summary>

 

 

 

/// To retrieve all directories

 

 

 

/// </summary>

 

 

 

/// <param name="path"></param>

 

 

 

/// <returns></returns>

 

 

 

private DirectoryItem[] GetChildDirectories(string path)

 

{

 

 

List<DirectoryItem> directories = new List<DirectoryItem>();

 

 

 

try

 

{

 

 

DataRow[] childRows = DataServer.GetDirectoryChildRows(path);

 

 

 

//DataRow[] childRows = DataServer.GetChildDirectoryRows(path);

 

 

 

int i = 0;

 

 

 

if (childRows != null)

 

{

 

 

while (i < childRows.Length)

 

{

 

 

DataRow childRow = childRows[i];

 

 

 

string name = childRow["FolderName"].ToString();

 

 

 

string itemFullPath = VirtualPathUtility.AppendTrailingSlash(CombinePath(path, name));

 

 

 

DirectoryItem newDirItem = new DirectoryItem(name,

 

 

 

string.Empty,

 

itemFullPath,

 

 

string.Empty,

 

GetPermissions(itemFullPath),

 

 

null, // The files are added in ResolveDirectory()

 

 

 

null // Directories are added in ResolveRootDirectoryAsTree()

 

);

directories.Add(newDirItem);

i = i + 1;

}

 

 

return directories.ToArray();

 

}

 

 

else

 

 

 

return new DirectoryItem[] { };

 

}

 

 

catch (Exception)

 

{

 

 

return new DirectoryItem[] { };

 

}

}

 

 

private string CombinePath(string path1, string path2)

 

{

 

 

if (path1.EndsWith("/"))

 

{

 

 

return string.Format("{0}{1}", path1, path2);

 

}

 

 

if (path1.EndsWith("\\"))

 

{

path1 = path1.Substring(0, path1.Length - 1);

}

 

 

return string.Format("{0}/{1}", path1, path2);

 

}

 

 

private FileItem[] GetChildFiles(string _path)

 

{

 

 

try

 

{

 

 

DataRow[] childRows = DataServer.GetChildFileRows(_path);

 

 

 

List<FileItem> files = new List<FileItem>();

 

 

 

for (int i = 0; i < childRows.Length; i++)

 

{

 

 

DataRow childRow = childRows[i];

 

 

 

string name = childRow["BlobUri"].ToString();

 

 

 

if (IsExtensionAllowed(System.IO.Path.GetExtension(name)))

 

{

 

 

string itemFullPath = CombinePath(_path, name);

 

 

 

string ss = GetItemUrl(itemFullPath);

 

 

 

//int n= name.LastIndexOf("/");

 

 

 

// string NA=name.Substring(n+1);

 

 

 

string itemname = childRow["ItemName"].ToString();

 

 

 

string rowKey = childRow["RowKey"].ToString();

 

 

 

FileItem newFileItem = new FileItem(itemname,

 

 

 

Path.GetExtension(name),

 

 

 

Convert.ToInt64(childRow["Size"]),

 

ss ,

GetItemUrl(itemFullPath),

rowKey ,

GetPermissions(itemFullPath)

);

 

newFileItem.Attributes.Add(

 

"id", rowKey);

 

files.Add(newFileItem);

}

}

 

 

return files.ToArray();

 

 

 

//return null;

 

}

 

 

catch (Exception)

 

{

 

 

return new FileItem[] { };

 

}

}

 

 

private bool IsExtensionAllowed(string extension)

 

{

 

 

return Array.IndexOf(SearchPatterns, "*.*") >= 0 || Array.IndexOf(SearchPatterns, "*" + extension.ToLower()) >= 0;

 

}

 

#endregion

}

}














 

<%

 

@ Page Title="" Language="C#" MasterPageFile="~/AdminStaff.master" AutoEventWireup="true"

 

 

 

 

 

 

 

CodeBehind="Files.aspx.cs" Inherits="LegalPaperwork.Admin.Files" %>

 

<%

 

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

 

 

 

<

 

 

asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">

 

 

 

 

 

 

 

<script type="text/javascript">

 

 

 

 

 

//<![CDATA[

 

 

 

 

 

 

 

 

 

</

 

 

script>

 

</

 

 

asp:Content>

 

<

 

 

asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >

 

 

 

 

 

 

 

 

<telerik:RadFileExplorer ID="fileExplorerFiles" runat="server"

 

 

 

ViewStateMode="Enabled"

 

 

 

Skin="Office2010Blue" EnableCreateNewFolder="True"

 

 

 

>

 

 

 

 

 

 

 

</telerik:RadFileExplorer>

 

</

 

 

asp:Content>

 

 

 

 












0
Dobromir
Telerik team
answered on 22 Nov 2011, 07:01 PM
Hi Praveen,

Could you please use the Format Code Block (please refer to the attached screenshot) when pasting code? Currently, the code that you have provided is unreadable.

Kind regards,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
General Discussions
Asked by
Praveen
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Praveen
Top achievements
Rank 1
Share this question
or