Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
38 views
I have a  grid which uses nested view templates like this http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx i'm using templates in both the master and detail.

According to my requirements the detail view should appear next to the master. When the grid renders there is 1 tr for the master row and another tr for the detail row. As far as i know there is no way to show tr next to each other in IE8

I've auto expanded the grid by default and hidden the expand columns. Basically the layout of what i'm looking for is like this:
parent1 | parent1_child1
              | parent1_child2
parent2 | parent2_child1 
              | parent2_child2

Any help will be greatly appreciated!
Veli
Telerik team
 answered on 20 May 2011
1 answer
30 views
I am encountering a strange bug? In my Telerik Drag and Drop enabled TreeView, if I click on a leaf (node with no children), a child will be automatically created. This appears to be Telerik specific as I am not catching any events in our js or server side code.
Is there a property/setting I need to change to avoid this behavior?

Thanks.
Veronica
Telerik team
 answered on 20 May 2011
6 answers
247 views
Here is what I would like to accomlish and cannot find in help:
Using the Dropdown list seen below, if user selects an option called "Other", a textbox pops up.  User can then type an option and on Save of webpage, it will be added to the DropDownList.  I need easiest most straightforward way to accomplish this.  Have not been able to find a lot of help.  Thank you.

Our version is: RadControls for ASPNET AJAX Q2 2008
Please let me know if you need any other information.

Thank you


<

 

telerik:RadGrid

 

 

runat="server"

 

 

ID="grdTypes"

 

 

Skin="Office2007"

 

 

EnableEmbeddedSkins="True"

 

 

AllowAutomaticDeletes="True"

 

 

AllowAutomaticUpdates="True"

 

 

AutoGenerateColumns="False"

 

 

AllowMultiRowEdit="True"

 

 

EnableAJAX="True"

 

 

GridLines="None"

 

 

Width="400px"

 

 

OnNeedDataSource="grdTypes_NeedDataSource"

 

 

OnDeleteCommand="grdTypes_DeleteCommand"

 

 

>

 

 

 

<ExportSettings>

 

 

<Pdf PageBottomMargin="" PageFooterMargin="" PageHeaderMargin="" PageHeight="11in"

 

 

PageLeftMargin="" PageRightMargin="" PageTopMargin="" PageWidth="8.5in" />

 

 

</ExportSettings>

 

 

<MasterTableView

 

 

CommandItemDisplay="Top"

 

 

EditMode="EditForms"

 

 

DataKeyNames="TypesID"

 

 

AutoGenerateColumns="false"

 

 

AllowSorting = "true">

 

 

 

<EditFormSettings>

 

 

<EditColumn CancelImageUrl="/next/RadControls/Grid/Skins/TEST/Cancel.gif" EditImageUrl="/next/RadControls/Grid/Skins/TEST/Edit.gif"

 

 

InsertImageUrl="/next/RadControls/Grid/Skins/TEST/Update.gif" UniqueName="EditCommandColumn2"

 

 

UpdateImageUrl="/next/RadControls/Grid/Skins/TEST/Update.gif">

 

 

</EditColumn>

 

 

</EditFormSettings>

 

 

 

<CommandItemTemplate >

 

 

<asp:LinkButton ID="InitInsertButton" runat="server" CommandName="InitInsert" >

 

 

<img alt="Add Record" src="/next/RadControls/Grid/Skins/TEST/AddRecord.gif" /> Add new record</asp:LinkButton>

 

 

</CommandItemTemplate>

 

 

 

<Columns>

 

 

 

<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderText="Edit">

 

 

<ItemStyle Width="10px"/>

 

 

</telerik:GridEditCommandColumn>

 

 

 

<telerik:GridButtonColumn

 

 

CommandName="Delete"

 

 

ConfirmText="Are you sure you wish to delete this record?"

 

 

Text="Delete"

 

 

HeaderText="Delete"

 

 

ImageUrl="/next/RadControls/Grid/Skins/Test/Delete.gif"

 

 

UniqueName= "DeleteColumn2"

 

 

ButtonType="ImageButton"

 

 

ShowSortIcon="False"

 

 

>

 

 

<ItemStyle Width="10px"/>

 

 

</telerik:GridButtonColumn>

 

 

 

<telerik:GridBoundColumn Visible="false" ReadOnly="true" DataField="TypesID" UniqueName="TypesID">

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridBoundColumn Visible="false" ReadOnly="true" DataField="DDID" UniqueName="DDID">

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridDropDownColumn

 

 

DataField="TypesID"

 

 

HeaderText="Types"

 

 

UniqueName="TypesID"

 

 

DataSourceID="myTypes"

 

 

ListValueField="TypesID"

 

 

ListTextField="TypeName"

 

 

DropDownControlType="DropDownList"

 

 

>

 

 

<ItemStyle Width="210px"/>

 

 

</telerik:GridDropDownColumn>

 

 

 

</Columns>

 

 

 

<ExpandCollapseColumn Resizable="False" Visible="False">

 

 

<HeaderStyle Width="20px" />

 

 

</ExpandCollapseColumn>

 

 

 

<RowIndicatorColumn Visible="False">

 

 

<HeaderStyle Width="20px" />

 

 

</RowIndicatorColumn>

 

 

 

</MasterTableView>

 

 

 

<FilterMenu EnableEmbeddedSkins="False" EnableTheming="True" Skin="TEST">

 

 

<CollapseAnimation Duration="200" Type="OutQuint" />

 

 

</FilterMenu>

 

 

 

</telerik:RadGrid>

 

Ronald de Bruijn
Top achievements
Rank 1
 answered on 20 May 2011
1 answer
47 views

I have a Template EditForm that contains a table with cells that contain an nested table with some text in the top row and a radio button in the bottom row. My problem is that I am unable to get the radio button to center in the nested table. I looked in the rendered html and I think that there are styles that are overriding my settings. Can you recommend how to accomplish centering the radio button?

Thanks,

Anne

 

 

 

<FormTemplate>

 

 

 

<table cellspacing="0" cellpadding="2" class="General">

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td colspan="5" class="DefaultGridCell"><br /><asp:Label ID="Edit_RubricTitle" runat="server" /></td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td class="DefaultGridCell">ELEMENT</td>

 

 

 

 

 

 

 

<td style="width:150px"class="DefaultGridCell">UNSATISFACTORY</td>

 

 

 

 

 

 

 

<td style="width:150px"class="DefaultGridCell">BASIC</td>

 

 

 

 

 

 

 

<td style="width:150px"class="DefaultGridCell">PROFICIENT</td>

 

 

 

 

 

 

 

<td style="width:150px"class="DefaultGridCell">DISTINGUISHED</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td class="DefaultGridCell" valign="top" align="center">

 

 

 

 

 

 

 

<asp:Label ID="Edit_ElementTitle" runat="server" />

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

<td class="DefaultGridCell" valign="top" align="center">

 

 

 

 

 

 

 

<table cellspacing="0" cellpadding="2">

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td align="center" valign="top"><asp:Label ID="Edit_DescriptorPL1" runat="server" /></td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

<asp:RadioButton ID="CB_DescriptorPL1" GroupName="Group1" runat="server" />

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

 

</td>

 

 

 

 

 

 

 

<td class="DefaultGridCell" valign="top" align="center">

 

 

 

 

 

 

 

<table cellspacing="0" cellpadding="2">

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td align="center" valign="top"><asp:Label ID="Edit_DescriptorPL2" runat="server" /></td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td align="center">

 

 

 

 

 

 

 

<asp:RadioButton ID="CB_DescriptorPL2" GroupName="Group1" runat="server" />

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

 

</td>

 

 

 

 

 

 

 

<td class="DefaultGridCell" valign="top" align="center">

 

 

 

<table cellspacing="0" cellpadding="2">

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td align="center" valign="top"><asp:Label ID="Edit_DescriptorPL3" runat="server" /></td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td align="center">

 

 

 

 

 

 

 

<asp:RadioButton ID="CB_DescriptorPL3" GroupName="Group1" runat="server" />

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

 

</td>

 

 

 

 

 

 

 

<td class="DefaultGridCell" valign="top" align="center">

 

 

 

<table cellspacing="0" cellpadding="2">

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td align="center" valign="top"><asp:Label ID="Edit_DescriptorPL4" runat="server" /></td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td align="center">

 

 

 

 

 

 

 

<asp:RadioButton ID="CB_DescriptorPL4" GroupName="Group1" runat="server" />

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

 

</td>

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

 

 

 

 

 

 

 

<br />

 

 

 

 

 

 

 

<table cellspacing="0" cellpadding="2" width="100%">

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td colspan="5">

 

 

 

 

 

 

 

<telerik:RadButton ID="btnUpdate" Text='<%# (Container is TreeListEditFormInsertItem) ? "Insert" : "Update" %>'

 

 

 

 

 

 

 

runat="server" CommandName='<%# (Container is TreeListEditFormInsertItem) ? "PerformInsert" : "Update" %>'

 

 

 

 

 

 

 

Icon-PrimaryIconCssClass="rbOk">

 

 

 

 

 

 

 

</telerik:RadButton>

 

 

 

 

 

 

 

&nbsp;

 

 

 

 

 

 

 

<telerik:RadButton ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"

 

 

 

 

 

 

 

CommandName="Cancel" Icon-PrimaryIconCssClass="rbCancel">

 

 

 

 

 

 

 

</telerik:RadButton>

 

 

 

 

 

 

 

</td>

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

 

 

 

 

 

</FormTemplate>

 

Daniel
Telerik team
 answered on 20 May 2011
1 answer
147 views
Hiya

Please could someone explain to me how i can access the DataKeyNames of a GridTableView from the code behind on the

ItemDataBound

 

of my parent radgrid...


Many thanks

 

 

 

 

 

 

Pavlina
Telerik team
 answered on 20 May 2011
2 answers
172 views
Hello

I have a grid with a template column like this
<telerik:GridTemplateColumn HeaderText="Program Id" AllowFiltering="true" Reorderable="true" SortExpression="Program_Id"
                    UniqueName="Program_Id" DataField="Program_Id">
                        <ItemTemplate>
                            <asp:Label ID="lblProgrammeId" runat="server" Text='<%# Eval("Program_Id") %>' />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox ID="txbProgrammeId" Width="50px" runat="server" TextMode="SingleLine"
                                Text='<%# Bind("Program_Id") %>' />
                            <telerik:RadButton ID="ValidateProgBtn" AutoPostBack="true" runat="server" Width="16px"
                                Height="16px" CommandName="ValidateProgId" ToolTip="Validate the programme id" Text="Cancel">
                                <Image ImageUrl="Images/1305817624_clean.png" />
                            </telerik:RadButton>
                             <%--OnClientClicked="ClearFields" OnClientClicking="OnClientButtonClickingHandler"--%>
                            <telerik:RadButton ID="RadButton1" AutoPostBack="true" Value="NoPostBack" runat="server" Width="16px"
                                Height="16px" CommandName="Clear All"
                                ToolTip="Clear the fields" Text="Clear">
                                <Image ImageUrl="Images/1305817654_edit-clear.png" />
                            </telerik:RadButton>
                            <asp:Label ID="IsNewProgLbl" runat="server" style="width:auto; color:Orange" Text=""></asp:Label>
                        </EditItemTemplate>
                        <ItemStyle VerticalAlign="Top" />
                 </telerik:GridTemplateColumn>

When I click the clear all button, in edit mode, I want the fields from the grid to be cleared and also set the readonly property to false( it is set to true in a previous state). So I set the command name, then catch it in RadGrid1_ItemCommand event handler and try to access  a field like this:
......
if (e.CommandName == "Clear All")
            {
                     
                    (e.Item.FindControl("txbProgrammeId") as RadTextBox).Text = "";
                    (e.Item.FindControl("txbProgrammeId") as RadTextBox).ReadOnly = false;
...........
But it seems that only the Label control exists! I can't find the RadTextBox or RadButton controls. I find this strange, since when the grid is in insert mode it works ok. I even tried to force the grid to be in edit mode
e.Item.Edit = true;
GridEditableItem editedItem = e.Item as GridEditableItem;
but still nothing.
Is there a way that I can use to solve this? Basically, I want a  button that clears some fields when the grid is in edit or insert mode.

Thx a lot.
Alin
Top achievements
Rank 1
 answered on 20 May 2011
1 answer
112 views
Hello, I'm having issue with css.
I'm adding dynamically css with OnLoad event:
function RequiredOnLoadHandler(sender) {
    if (sender.isEmpty()) {
        $(sender._textBoxElement).addClass("requiredEmpty");
    }
}
But is gone on mouse over. I'm having problem with. It automatically removes that added class. Could you help me, how to avoid removing that css class.?
Princy
Top achievements
Rank 2
 answered on 20 May 2011
1 answer
145 views
Hi,

Is it possible to use the same XML data source for both a RadMenu and a RadTreeView?

I am trying to convert an existing (non-Telerik) menu administration page over to use Telerik controls.  The page displays the menu XML data as a tree view and allows the users to edit, add, and delete nodes.  The XML content is in a database and is loaded using the LoadXML() method.  Upon saving changes, the data is serialized back out using GetXML(), and the XML is written back to the database.

The reason I ask is because the XML formats for the two controls listed in the documentation are different:

RadMenu XML Format
<Menu Skin="Outlook">
    <Item Text="Parent" LeftLogo="Img\parent.gif" >
        <Group Width="140" Flow="Vertical">
            <Item Text="Child 1" />
            <Item IsSeparator="True" />
            <Item Text="Child 2" />
        </Group>
    </Item>
</Menu>

RadTreeView XML Format
<Tree>
  <Node Text="North America" Expanded="True" Value="1">
    <Node>
       <Node>
       </Node>
    </Node>
  </Node>
</Tree>


If it is not possible to load RadMenu XML data into a RadTreeView item directly, do you have any suggestions on how to achieve the same or similar effect?

Thanks,
Kevin
Kate
Telerik team
 answered on 20 May 2011
1 answer
73 views
I'm trying to open a radwindow inside of another radwindow.  It works fine in IE 7, but in firefox and IE 8, the window opens and starts to load, but it closes after a few seconds.  My code is below.
function OnClientClose(oWnd, args) {
    //get the transferred arguments
    var arg = args.get_argument();
    if (arg) {
        var clientId = arg.ClientId;
        var txtClientId = $find("<%= txtNewlclient.ClientID %>");
        txtClientId.set_value(clientId.toString());
 
    }
}
function showClientSearch() {
 
    window.radopen("../../Sections/Clients/ClientSearch.aspx", "rwindClientSearch");
}
and my radwindow declaration

<telerik:RadWindowManager ID="rwindMgr" runat="server">
    <Windows>
        <telerik:RadWindow ID="rwindClientSearch" Title="Client Search" runat="server"
            Width="350px" Height="300px" OnClientClose="OnClientClose" ReloadOnShow="true" ShowContentDuringLoad="false">
        </telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>

This code works in other places when it's not inside of another radwindow.
Marin Bratanov
Telerik team
 answered on 20 May 2011
1 answer
204 views
Hi,
I have recently started using the FileExplorer control for a file manager within our backend. Our system works with absolute paths (instead of relative), hence I implemented a custom FileBrowserContentProvider.

Everything works fine except for one single thing: when renaming a file from, for example, 'NewFileName.jpg' to 'File1.jpg', the file is renamed to 'NewFileName.jpgFile1.jpg' (the old file name and new file name are concatenated). This issue is only present withfile renaming. File move, directory move and directory rename all work fine. The parameter newPath in the MoveFile function within the content provider is already being supplied in a wrong manner (already concatenated). When I implemented the OnClientMove JavaScript function, the args.get_newPath(), however, was being shown as the proper new final.

I have no idea what else I can check for this to see what's going wrong. I attached my custom FileBrowserContentProvider hoping it may help.

Thanks,
Edward

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Web.UI.Widgets;
using System.Drawing.Imaging;
using System.Collections;
using System.IO;
using System.Drawing;
using Telerik.Web.UI;
using ICON.Management.Framework.LinqContexts;
using Icon.Common.Data;
using System.Text;
 
namespace ICON.Management.Framework.MediaLibrary
{
    public class IconFileBrowserContentProvider : FileBrowserContentProvider
    {
        #region DirectoryLister
        private class DirectoryLister
        {
            public DirectoryLister(IconFileBrowserContentProvider contentProvider, bool includeFiles, bool includeDirectories)
            {
                _contentProvider = contentProvider;
 
                _includeFiles = includeFiles;
                _includeDirectories = includeDirectories;
            }
 
 
            protected bool IsParentOf(string virtualParent, string virtualChild)
            {
                return _contentProvider.IsParentOf(virtualParent, virtualChild);
            }
 
            protected FileItem[] GetFiles(DirectoryInfo directory, PathPermissions permissions, string location)
            {
                ArrayList files = new ArrayList();
                Hashtable fileNames = new Hashtable();
                foreach (string searchPattern in _contentProvider.SearchPatterns)
                {
                    FileInfo[] fs = directory.GetFiles(searchPattern);
                    for (int i = 0; i < fs.Length; i++)
                    {
                        FileInfo file = fs[i];
                        if (!fileNames.ContainsKey(file.FullName) && _contentProvider.IsValid(file))
                        {
                            fileNames.Add(file.FullName, string.Empty);
 
                            //In list mode we need the tag because with the different folder structure
                            // we are unable to build proper urls for the files
                            string tag = IsListMode ? location + file.Name : string.Empty;
 
                            files.Add(new FileItem(file.Name, file.Extension, file.Length, string.Empty, string.Empty, tag, permissions));
                        }
                    }
                }
                return (FileItem[])files.ToArray(typeof(FileItem));
            }
 
            protected DirectoryItem[] GetDirectories(DirectoryInfo directory, string parentPath)
            {
                DirectoryInfo[] dirs = directory.GetDirectories();
                ArrayList directories = new ArrayList();
                for (int i = 0; i < dirs.Length; i++)
                {
                    DirectoryInfo dir = dirs[i];
                    if (_contentProvider.IsValid(dir))
                    {
                        directories.Add(GetDirectory(dir, VirtualPathUtility.AppendTrailingSlash(parentPath) + dir.Name));
                    }
                }
                return (DirectoryItem[])directories.ToArray(typeof(DirectoryItem));
            }
 
 
            public DirectoryItem GetDirectory(DirectoryInfo dir, string virtualName, string location, string fullPath, string tag)
            {
                PathPermissions permissions = _contentProvider.GetPermissions(fullPath);
 
                bool includeDirectories = IsListMode ? IncludeDirectories : IsParentOf(fullPath, SelectedUrl);
                bool includeFiles = IsParentOf(fullPath, SelectedUrl);
 
                DirectoryItem[] subdirectories = IncludeDirectories ? GetDirectories(dir, fullPath) : new DirectoryItem[] { };
                FileItem[] files = IncludeFiles ? GetFiles(dir, permissions, fullPath + "\\") : new FileItem[] { };
 
                DirectoryItem item = new DirectoryItem(virtualName, location, fullPath, tag, permissions, files, subdirectories);
                item.Attributes.Add("Date Created", DateTime.Now.ToString());
 
                return item;
            }
 
            public DirectoryItem GetDirectory(DirectoryInfo dir, string fullPath)
            {
                string tag = IsListMode ? fullPath : string.Empty;
                return GetDirectory(dir, dir.Name, string.Empty, fullPath, tag);
            }
 
 
            protected bool IsListMode
            {
                get
                {
                    return false;
                }
            }
 
            protected string SelectedUrl
            {
                get
                {
                    return _contentProvider.SelectedUrl;
                }
            }
 
 
            protected bool IncludeFiles
            {
                get
                {
                    return _includeFiles;
                }
            }
 
            protected bool IncludeDirectories
            {
                get
                {
                    return _includeDirectories;
                }
            }
 
            private IconFileBrowserContentProvider _contentProvider;
            private bool _includeFiles;
            private bool _includeDirectories;
        }
 
        #endregion
 
        #region DirectoryFlattener
        private class DirectoryFlattener
        {
            private ArrayList _directories = new ArrayList();
 
            public DirectoryFlattener(DirectoryItem item)
            {
                if (item == null)
                {
                    return;
                }
 
                Flatten(item);
 
                _directories.Add(item);
            }
 
            private void Flatten(DirectoryItem item)
            {
                foreach (DirectoryItem subdirectory in item.Directories)
                {
                    Flatten(subdirectory);
                }
 
                _directories.AddRange(item.Directories);
 
                item.ClearDirectories();
            }
 
            public DirectoryItem[] Directories
            {
                get
                {
                    return (DirectoryItem[])_directories.ToArray(typeof(DirectoryItem));
                }
            }
        }
 
        #endregion
 
        public IconFileBrowserContentProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
            : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
        {
            ProcessPaths(ViewPaths);
            ProcessPaths(UploadPaths);
            ProcessPaths(DeletePaths);
            SelectedUrl = RemoveProtocolNameAndServerName(GetAbsolutePath(SelectedUrl));
        }
 
 
        protected virtual bool IsValid(FileInfo file)
        {
            return true;
        }
 
        protected virtual bool IsValid(DirectoryInfo directory)
        {
            return true;
        }
 
        public override DirectoryItem ResolveRootDirectoryAsTree(string path)
        {
            string physicalPath = path;
 
            DirectoryInfo info = new DirectoryInfo(path);
 
            if (!info.Exists)
            {
                return null;
            }
 
            string virtualName = info.Name;
 
            if (UploadPaths.Contains(path)
                || ViewPaths.Contains(path)
                || DeletePaths.Contains(path))
            {
                using (IconStorageCentralContext context = DbUtils.IconStorageCentralDataContext)
                {
                    virtualName = (from libraries in context.Libraries
                                    where libraries.Id == int.Parse(info.Name)
                                     select libraries.Name).Single();
                }
            }
 
            string virtualParentPath = info.Parent.FullName;
 
            DirectoryLister directoryLister = new DirectoryLister(this, false, true);
 
            return directoryLister.GetDirectory(info, virtualName, virtualParentPath, path, string.Empty);
        }
 
 
        public override DirectoryItem ResolveDirectory(string path)
        {
            string physicalPath = path;
 
            DirectoryInfo dir = new DirectoryInfo(physicalPath);
            if (!dir.Exists)
            {
                return null;
            }
 
            DirectoryLister directoryLister = new DirectoryLister(this, true, false);
 
            return directoryLister.GetDirectory(dir, path);
        }
 
        public override bool CanCreateDirectory
        {
            get
            {
                return true;
            }
        }
 
        public override string GetFileName(string url)
        {
            return Path.GetFileName(RemoveProtocolNameAndServerName(GetAbsolutePath(url)));
        }
 
        public override string GetPath(string url)
        {
            string virtualPath = RemoveProtocolNameAndServerName(GetAbsolutePath(url));
 
            return virtualPath;
        }
 
        public override Stream GetFile(string url)
        {
            string physicalPath = url;
 
            if (!System.IO.File.Exists(physicalPath))
            {
                return null;
            }
 
            return System.IO.File.OpenRead(physicalPath);
        }
 
        public override string StoreBitmap(Bitmap bitmap, string url, ImageFormat format)
        {
            bitmap.Save(url, format);
 
            return url;
        }
 
        public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)
        {
            string targetFullPath = Path.Combine(path, name);
            if (System.IO.File.Exists(targetFullPath))
            {
                System.IO.File.Delete(targetFullPath);
            }
            //normalize slashes
            file.SaveAs(targetFullPath);
            return targetFullPath;
        }
 
        public override string DeleteFile(string path)
        {
            string physicalPath = path;
            try
            {
                if (System.IO.File.Exists(physicalPath))
                {
                    if ((System.IO.File.GetAttributes(physicalPath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        return "FileReadOnly";
                    }
                    System.IO.File.Delete(physicalPath);
                }
            }
            catch (UnauthorizedAccessException)
            {
                return "NoPermissionsToDeleteFile";
            }
            return string.Empty;
        }
 
        public override string DeleteDirectory(string path)
        {
            string physicalPath = path;
            try
            {
                if (Directory.Exists(physicalPath))
                {
                    Directory.Delete(physicalPath, true);
                }
            }
            catch (UnauthorizedAccessException)
            {
                return "NoPermissionsToDeleteFolder";
            }
            return string.Empty;
        }
 
        public override string CreateDirectory(string path, string name)
        {
            if (name.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
            {
                return "InvalidCharactersInPath";
            }
            string newFolderPath = (path + name);
            if (Directory.Exists(newFolderPath))
            {
                return "DirectoryAlreadyExists";
            }
            try
            {
                Directory.CreateDirectory(newFolderPath);
            }
            catch (UnauthorizedAccessException)
            {
                return "NoPermissionsToCreateFolder";
            }
            catch (Exception e)
            {
                return e.Message;
            }
            return string.Empty;
        }
 
        public override string MoveDirectory(string path, string newPath)
        {
            string oldPhysicalPath = path;
            string newPhysicalPath = newPath;
            try
            {
                Directory.Move(oldPhysicalPath, newPhysicalPath);
            }
            catch (Exception e)
            {
                return e.Message;
            }
            return string.Empty;
        }
 
        public override string MoveFile(string path, string newPath)
        {
            string oldPhysicalPath = path;
            string newPhysicalPath = newPath;
            if (!System.IO.File.Exists(oldPhysicalPath))
                return "FileNotFound";
            if (System.IO.File.Exists(newPhysicalPath))
                return "NewFileAlreadyExists";
            try
            {
                System.IO.File.Move(oldPhysicalPath, newPhysicalPath);
            }
            catch (UnauthorizedAccessException)
            {
                return "NoPermissionsToMoveFile";
            }
            return string.Empty;
        }
 
        public void ProcessPaths(string[] paths)
        {
            for (int i=0; i < paths.Length; i++)
            {
                paths[i] = GetAbsolutePath(paths[i]);
            }
        }
 
 
        protected string GetAbsolutePath(string path)
        {
            if (path.StartsWith("~"))
            {
                path = VirtualPathUtility.AppendTrailingSlash(VirtualPathUtility.AppendTrailingSlash(Context.Request.ApplicationPath) + path.Substring(2));
 
                return path.Substring(0, path.Length - 1);
            }
            return path;
        }
 
 
        protected bool IsParentOf(string virtualParent, string virtualChild)
        {
            //original function did not cover all cases - e.g. parent="/test" and child="/testing" should return false
            if (virtualChild.ToLower().StartsWith(virtualParent.ToLower()))
            {
                if (virtualParent.Length == virtualChild.Length)
                {
                    return true;
                }
                else
                {
                    //if the parent ends with slash, or the child has a slash after the parent part
                    //we should be OK
                    int len = virtualParent.Length;
                    if (virtualChild[len] == '/' || virtualChild[len] == '\\' ||
                        virtualChild[len - 1] == '/' || virtualChild[len - 1] == '\\')
                        return true;
                }
            }
            return false;
        }
 
        protected PathPermissions GetPermissions(string path)
        {
            PathPermissions permissions = PathPermissions.Read;
            if (CanUpload(path))
                permissions |= PathPermissions.Upload;
            if (CanDelete(path))
                permissions |= PathPermissions.Delete;
 
            return permissions;
        }
 
        protected bool CanUpload(string path)
        {
            foreach (string uploadPath in UploadPaths)
            {
                if (IsParentOf(uploadPath, path))
                {
                    return true;
                }
            }
            return false;
        }
 
        protected bool CanDelete(string path)
        {
            foreach (string deletePath in DeletePaths)
            {
                if (IsParentOf(deletePath, path))
                {
                    return true;
                }
            }
            return false;
        }
 
         
    }
}
Dobromir
Telerik team
 answered on 20 May 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?