Tuesday, June 17, 2014

Administration Page for ASP.NET VirtualPathProvider


If you read this Microsoft Support article: http://support.microsoft.com/kb/910441, you will notice that the Administration Page provided is very primitive and will not display any content if the database is empty.  Of course, you can manually edit the content in the database, but it is probably easier to have an Administration Page that will help you initially load that content directly into the database.
I am partial to the Telerik RadControls, therefore, I used the Telerik RadGrid control in my Administration Page, but you can use whichever control you prefer.  Below is the sample code that I used for my Administration Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SharePointAdministrationPage.aspx.cs" Inherits="SPVPP.SharePointAdministrationPage" %>

 

<%@ register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

 

<!DOCTYPE html>

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

        <telerik:radscriptmanager id="RadScriptManager1" runat="server">

            <scripts>

                <asp:scriptreference assembly="Telerik.Web.UI" name="Telerik.Web.UI.Common.Core.js"></asp:scriptreference>

                <asp:scriptreference assembly="Telerik.Web.UI" name="Telerik.Web.UI.Common.jQuery.js"></asp:scriptreference>

                <asp:scriptreference assembly="Telerik.Web.UI" name="Telerik.Web.UI.Common.jQueryInclude.js"></asp:scriptreference>

            </scripts>

        </telerik:radscriptmanager>

        <div>

            <telerik:radgrid id="RadGrid1" runat="server" autogeneratecolumns="False" datasourceid="SqlDataSource1" allowautomaticinserts="True" allowautomaticupdates="True" cellspacing="-1" gridlines="Both">

                <mastertableview datakeynames="FileName" datasourceid="SqlDataSource1" commanditemdisplay="Top" allowautomaticinserts="True" allowautomaticupdates="True" nomasterrecordstext="No records found">

                    <commanditemsettings showaddnewrecordbutton="True" showcancelchangesbutton="True" showrefreshbutton="True"></commanditemsettings>

                    <columns>

                        <telerik:grideditcommandcolumn buttontype="ImageButton" uniquename="EditCommandColumn" />

                        <telerik:gridboundcolumn datafield="FileName" filtercontrolalttext="Filter FileName column" headertext="FileName" sortexpression="FileName" uniquename="FileName">

                        </telerik:gridboundcolumn>

                        <telerik:gridboundcolumn datafield="FileData" filtercontrolalttext="Filter FileData column" headertext="FileData" sortexpression="FileData" uniquename="FileData">

                        </telerik:gridboundcolumn>

                        <telerik:gridhyperlinkcolumn datatextfield="VirtualPath" target="_self" headertext="Virtual Path" datanavigateurlformatstring="{0}" datanavigateurlfields="VirtualPath" />

                        <telerik:gridbuttoncolumn text="Delete" commandname="Delete" buttontype="ImageButton" />

                    </columns>

                    <editformsettings editformtype="Template">

                        <formtemplate>

                            <table id="Table3" cellspacing="1" cellpadding="1" width="100%" border="0">

 

                                <tr>

                                    <td>FileName:

                                    </td>

                                    <td>

                                        <asp:textbox id="txtFileName" runat="server" text='<%# Bind("FileName") %>' />

                                    </td>

                                </tr>

                                <tr>

                                    <td>FileData:

                                    </td>

 

                                    <td>

                                        <telerik:radeditor id="txtFileDataContent" runat="server" content='<%#Bind("FileData") %>'></telerik:radeditor>

                                    </td>

                                </tr>

                                <tr>

                                    <td>VirtualPath:

                                    </td>

                                    <td>

                                        <asp:textbox id="txtVirtualPath" runat="server" text='<%# Bind("VirtualPath") %>' />

                                    </td>

                                </tr>

                                <tr>

                                    <td align="right" colspan="2">

                                        <asp:button id="btnUpdate" text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'

                                            runat="server" commandname='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:button>&nbsp;

                                <asp:button id="btnCancel" text="Cancel" runat="server" causesvalidation="False"

                                    commandname="Cancel"></asp:button>

                                    </td>

                                </tr>

                        </formtemplate>

                    </editformsettings>

                </mastertableview>

            </telerik:radgrid>

            <asp:sqldatasource id="SqlDataSource1" runat="server"

                connectionstring="<%$ ConnectionStrings:VirtualProviderDBConnectionString %>" insertcommand="USP_INSERT_PAGE" insertcommandtype="StoredProcedure" selectcommand="USP_SELECT_PAGE" selectcommandtype="StoredProcedure" updatecommand="USP_EDIT_PAGE" updatecommandtype="StoredProcedure">

                <insertparameters>

                    <asp:parameter name="FileName" type="String" />

                    <asp:parameter name="FileData" type="String" />

                    <asp:parameter name="VirtualPath" type="String" />

                </insertparameters>

                <updateparameters>

                    <asp:parameter name="FileName" type="String" />

                    <asp:parameter name="FileData" type="String" />

                    <asp:parameter name="VirtualPath" type="String" />

                </updateparameters>

            </asp:sqldatasource>

        </div>

    </form>

</body>

</html>
I also used stored procedures to manage my Select, Insert and Update commands to provide greater security for inserting such content directly into the database.

No comments:

Post a Comment