Admin rights for uploaded files

Last post 04-04-2006 9:34 PM by pdqjohnny. 4 replies.

Sort Posts:

  • Admin rights for uploaded files

    04-02-2006, 9:52 PM
    • Member
      40 point Member
    • pdqjohnny
    • Member since 12-29-2003, 4:55 PM
    • Posts 8

    This is for the Club Web Site Starter Kit Extended  Edition that put an upload file addition on the site.

    You can mark a file that you upload to the site as PUBLIC viewable or not.

    When it is not PUBLIC it will not show on the docs.aspx gridveiw only PUBLIC files show-up.

    I want the files to show if you are an ADMINISTRATOR.

    I know if I make another page just for the ADMINISTRATOR I can get it to show all files by avoiding the IsPublic WHERE
    Must be a better way.
    Reason: I want all files to show if an ADMINISTRATOR, so other ADMINISTRATOR whom are not designing the web site can view and download files that have been uploaded by other Administrators.

    Thanks In Advance for your help

    Here is the present code that brings back the PUBLIC files.

    SelectCommand="SELECT * FROM [DocumentCategories] WHERE ([IsPublic] = @IsPublic) ORDER BY [CategoryName]">
                      
                        <SelectParameters>
                            <asp:Parameter DefaultValue="true" Name="IsPublic" Type="Boolean" />
                        </SelectParameters>

  • Re: Admin rights for uploaded files

    04-04-2006, 3:22 PM
    • Participant
      1,397 point Participant
    • MaineOne
    • Member since 01-20-2006, 1:00 AM
    • Maine
    • Posts 337

    This is for the Club Web Site Starter Kit Extended  Edition that put an upload file addition on the site. ???

    If I'm reading this right your saying you have a CSK extended edition?  If so where did you get it from, just curious.

    I have a File sharing addon I just developed, it does have the ability to set the ViewStatus to Public, Authenticated or Administrators. it is a simple Radio button selection when you add a file or edit a file.

    aspsksolutions.com

  • Re: Admin rights for uploaded files

    04-04-2006, 3:27 PM
    • Participant
      1,397 point Participant
    • MaineOne
    • Member since 01-20-2006, 1:00 AM
    • Maine
    • Posts 337
    Think I just figured out you meant the Extend the kit (whitepaper)  , I did not use this but I will take a look and see if I can help.
    aspsksolutions.com

  • Re: Admin rights for uploaded files

    04-04-2006, 4:19 PM
    • Participant
      1,680 point Participant
    • samsp
    • Member since 08-08-2002, 5:35 PM
    • Posts 330
    • AspNetTeam

    You can do this by adding an OR to the sql query. For example:

    SelectCommand="SELECT * FROM [DocumentCategories] WHERE (([IsPublic] = @IsPublic) OR (@isAdmin= TRUE)) ORDER BY [CategoryName]">
                      
                        <SelectParameters>
                            <asp:Parameter DefaultValue="true" Name="IsPublic" Type="Boolean" />

                            <asp:Parameter DefaultValue="false" Name="isAdmin" Type="Boolean" />
                        </SelectParameters>

    You then need to set the value of the parameter when the datasource is bound. The code below is probably wrong as I just flattened my laptop and don't have VS installed, but should be close enough to give the right idea.

        protected void SqlDataSource1_Selecting(object sender, System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs e)
        {
            if (User.Identity.IsAuthenticated && User.IsInRole("Administrators"))
            {
                e.Command.Parameters["@isAdmin"].Value = True;
            }
        }

    Sam

  • Re: Admin rights for uploaded files

    04-04-2006, 9:34 PM
    • Member
      40 point Member
    • pdqjohnny
    • Member since 12-29-2003, 4:55 PM
    • Posts 8

    Your help is greatly appreciated. I'm putting here more of the code with your suggested changes included. I see where the DataBinding takes place. But I do not know where to put the Data Bound protected void code you have provided. Can you continue with your help?

    </

    asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"

    SelectCommand="SELECT * FROM [DocumentCategories] WHERE ([IsPublic] = @IsPublic) OR (@isAdmin= TRUE)) ORDER BY [CategoryName]">

    <SelectParameters>

    <asp:Parameter DefaultValue="true" Name="IsPublic" Type="Boolean" />

    <asp:Parameter DefaultValue="false" Name="isAdmin" Type="Boolean" />

    </SelectParameters>

    </asp:SqlDataSource>

    &nbsp;

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

    AutoGenerateColumns="False" DataKeyNames="DocumentID" DataSourceID="SqlDataSource2">

    <Columns>

    <asp:TemplateField HeaderText="DocumentName" SortExpression="DocumentName">

    <EditItemTemplate>

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DocumentName") %>'></asp:TextBox>

    </EditItemTemplate>

    <ItemTemplate>

    <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Eval ("DocumentName", "~\Files\{0}") %>'

    Text='<%# Eval ("DocumentName") %>'></asp:HyperLink>

    </ItemTemplate>

    </asp:TemplateField>

    <asp:BoundField DataField="DateInput" HeaderText="DateInput" SortExpression="DateInput" />

    <asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />

    </Columns>

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"

    SelectCommand="SELECT * FROM [Documents] WHERE ([DocumentCategory] = @DocumentCategory) ORDER BY [DateInput] DESC">

    <SelectParameters>

    <asp:QueryStringParameter Name="DocumentCategory" QueryStringField="categoryid" Type="Int32" />

    </SelectParameters>
Page 1 of 1 (5 items)