clubsite whitepaper errors?

Rate It (2)

Last post 05-09-2007 4:38 AM by bradf99. 24 replies.

Sort Posts:

  • clubsite whitepaper errors?

    07-11-2005, 10:44 AM
    • Loading...
    • gtjr921
    • Joined on 10-27-2004, 11:22 AM
    • Cincinnati
    • Posts 156
    Has anyone read through the white papers on this starter kit? They seem somewhat incomplete. For instace there are a few paes where I see browse buttons to upload files, but never given the code on the best way to do this. Especially in the extending the club site between figure 14 and 15 it mentions that the code for button 2 click will be shown shortly, but it is never shown. "These are the parameters that we will generate dynamically in the Button2_Click event (shown shortly)"

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/clubwebsitesk.asp

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/extendclubwebsitesk.asp
  • Re: clubsite whitepaper errors?

    07-15-2005, 1:04 PM
    • Loading...
    • Bill Evjen
    • Joined on 06-18-2002, 6:07 AM
    • St. Louis, Missouri
    • Posts 4
    • ASPInsiders
    You get the Browse button by using a FileUpload server control. This is part of the control and shows up automatically.

    Bill Evjen
  • Re: clubsite whitepaper errors?

    07-27-2005, 10:05 AM
    • Loading...
    • rmoynihan
    • Joined on 06-24-2005, 8:36 PM
    • Posts 2

    Getting the browse button is not a problem, but i don't know what code to put behind this button as it does not go through this in the whitepaper for extendind the clubsite.

    All it says is,

    "These are the parameters that we will generate dynamically in the Button2_Click event (shown shortly)"

    But it is not shown after this or anywhere in the whitepaper.
    The code missing for this button should be the code to upload the document and store its details in the database.
    You cannot upload files without it

    Regards,

    Ronan. 

  • Re: clubsite whitepaper errors?

    08-05-2005, 7:23 PM
    • Loading...
    • Reese5150
    • Joined on 06-14-2004, 6:22 PM
    • Washington State
    • Posts 2
    I agree.  An otherwise excellent paper is seriously marred by the exclusion of this important piece.  I was able to kludge past it with some less-than-elegant coding to get files to upload (email me for details), but I suspect Mr. Evjen has a much better solution for us.
    -Reese

  • Indifferent [:|] Re: clubsite whitepaper errors?

    08-07-2005, 8:08 AM
    • Loading...
    • scottt40
    • Joined on 09-05-2002, 2:26 PM
    • CT
    • Posts 165

    I found the white paper on Extending the Club site very useful in many ways as a relative novice to programming, not to site dev:

    1. I finally learned about insert parameter syntax, and how to use it in a button click event to create a simple form without using the FormView Button. Thanks!
    2. I learned how to create and consume querry strings in a hyperlink and use the in a datalist control or other control to redirect. Thanks!
    3. I learned how to create a Shared Documents section for my site!!! Thanks!

    Now all you have to do is post the page code for the add documents page, or/ and button click event for Button 2.  PLEASE!!!!!

    Thanks Scott
  • Re: clubsite whitepaper errors?

    08-13-2005, 8:27 AM
    • Loading...
    • Bill Evjen
    • Joined on 06-18-2002, 6:07 AM
    • St. Louis, Missouri
    • Posts 4
    • ASPInsiders

    Sorry. I was on vacation up near the artic circle for awhile (really!). Here is the code for the Button2_Click event:

        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            If FileUpload1.HasFile Then
                Try
                    FileUpload1.SaveAs(Server.MapPath("~\Files\" & FileUpload1.FileName.ToString()))
                    Label1.Text = "<b>File Successfully Uploaded!</b><br />"
                   
                    SqlDataSource2.DeleteParameters.Add("DeleteDocumentName", FileUpload1.FileName.ToString())
                    SqlDataSource2.Delete()
                                 
                    SqlDataSource2.InsertParameters.Add("DocumentName", FileUpload1.FileName.ToString())
                    SqlDataSource2.InsertParameters.Add("DateInput", DateTime.Now.ToString())
                   
                    SqlDataSource2.Insert()
                Catch ex As Exception
                    Label1.Text = "ERROR IN UPLOADING: " & ex.Message.ToString()
                Finally
                    TextBox2.Text = ""
                End Try
            End If
        End Sub

    Here is the code for the entire page:

    <%@ Page Language="VB" MasterPageFile="~/Default.master" Title="Untitled Page" MaintainScrollPositionOnPostback="true" %>

    <script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            SqlDataSource1.Insert()
            TextBox1.Text = ""
            CheckBox1.Checked = False
    End Sub

        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            If FileUpload1.HasFile Then
                Try
                    FileUpload1.SaveAs(Server.MapPath("~\Files\" & FileUpload1.FileName.ToString()))
                    Label1.Text = "<b>File Successfully Uploaded!</b><br />"
                   
                    SqlDataSource2.DeleteParameters.Add("DeleteDocumentName", FileUpload1.FileName.ToString())
                    SqlDataSource2.Delete()
                                 
                    SqlDataSource2.InsertParameters.Add("DocumentName", FileUpload1.FileName.ToString())
                    SqlDataSource2.InsertParameters.Add("DateInput", DateTime.Now.ToString())
                   
                    SqlDataSource2.Insert()
                Catch ex As Exception
                    Label1.Text = "ERROR IN UPLOADING: " & ex.Message.ToString()
                Finally
                    TextBox2.Text = ""
                End Try
            End If
        End Sub
    </script>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <div id="body">
            <div class="fullwidth">
                <h2>File Category System</h2>
                <p>
                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="SqlDataSource1" EmptyDataText="There are no categories present." Width="100%">
                        <Columns>
                            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                            <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
                                ReadOnly="True" SortExpression="CategoryID" />
                            <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
                            <asp:CheckBoxField DataField="IsPublic" HeaderText="IsPublic" SortExpression="IsPublic" />
                        </Columns>
                    </asp:GridView>
                    &nbsp;<p>
                        <strong><span style="text-decoration: underline">Add a New Category</span></strong></p>
                <p>
                        Category Name:<br />
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></p>
                <p>
                    <asp:CheckBox ID="CheckBox1" runat="server" Text="Check if category is public" />&nbsp;</p>
                <p>
                    <asp:Button ID="Button1" runat="server" Text="Add Category" OnClick="Button1_Click" />
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>" DeleteCommand="DELETE FROM [DocumentCategories] WHERE [CategoryID] = @original_CategoryID" InsertCommand="INSERT INTO [DocumentCategories] ([CategoryName], [IsPublic]) VALUES (@CategoryName, @IsPublic)" SelectCommand="SELECT * FROM [DocumentCategories]" UpdateCommand="UPDATE [DocumentCategories] SET [CategoryName] = @CategoryName, [IsPublic] = @IsPublic WHERE [CategoryID] = @original_CategoryID">
                        <DeleteParameters>
                            <asp:Parameter Name="original_CategoryID" Type="Int32" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="CategoryName" Type="String" />
                            <asp:Parameter Name="IsPublic" Type="Boolean" />
                            <asp:Parameter Name="original_CategoryID" Type="Int32" />
                        </UpdateParameters>
                        <InsertParameters>
                            <asp:ControlParameter Name="CategoryName" Type="String" ControlID="TextBox1" />
                            <asp:ControlParameter Name="IsPublic" Type="Boolean" ControlID="CheckBox1" />
                        </InsertParameters>
                    </asp:SqlDataSource>
                </p>           
            </div>
           
            <div class="fullwidth">
                <h2>File Management System</h2>
                <p>
                    <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True"
                        AutoGenerateColumns="False" DataKeyNames="DocumentID" DataSourceID="SqlDataSource2"
                        EmptyDataText="There are no files present." Width="100%">
                        <Columns>
                            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                            <asp:BoundField DataField="DocumentID" HeaderText="DocumentID" InsertVisible="False"
                                ReadOnly="True" SortExpression="DocumentID" />
                            <asp:BoundField DataField="DocumentName" HeaderText="DocumentName" SortExpression="DocumentName" ReadOnly="True" />
                            <asp:BoundField DataField="DateInput" HeaderText="DateInput" SortExpression="DateInput" />
                            <asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
                            <asp:BoundField DataField="DocumentCategory" HeaderText="DocumentCategory" SortExpression="DocumentCategory" />
                            <asp:CheckBoxField DataField="TopDoc" HeaderText="TopDoc" SortExpression="TopDoc" />
                        </Columns>
                    </asp:GridView>
                    &nbsp;</p>
                <p>
                    <strong><span style="text-decoration: underline">Add a New File</span></strong></p>
                <p>
                    Select Category:<br />
                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
                        DataTextField="CategoryName" DataValueField="CategoryID">
                    </asp:DropDownList></p>
                <p>
                    File Comments:<br />
                    <asp:TextBox ID="TextBox2" runat="server" Width="350px"></asp:TextBox></p>
                <p>
                    Show up on Top-Document List?
                    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                        <asp:ListItem Value="true">Yes</asp:ListItem>
                        <asp:ListItem Selected="True" Value="false">No</asp:ListItem>
                    </asp:RadioButtonList></p>
                <p>
                    File to Upload:<br />
                    <asp:FileUpload ID="FileUpload1" runat="server" Width="350px" /></p>
                <p>
                    <asp:Button ID="Button2" runat="server" Text="Upload File" OnClick="Button2_Click" />&nbsp;</p>
                <p>
                    <asp:Label ID="Label1" runat="server"></asp:Label><br />
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
                        DeleteCommand="DELETE FROM [Documents] WHERE [DocumentID] = @original_DocumentID"
                        InsertCommand="INSERT INTO [Documents] ([DocumentName], [DateInput], [Comments], [DocumentCategory], [TopDoc]) VALUES (@DocumentName, @DateInput, @Comments, @DocumentCategory, @TopDoc)"
                        SelectCommand="SELECT * FROM [Documents]" UpdateCommand="UPDATE [Documents] SET [DocumentName] = @DocumentName, [DateInput] = @DateInput, [Comments] = @Comments, [DocumentCategory] = @DocumentCategory, [TopDoc] = @TopDoc WHERE [DocumentID] = @original_DocumentID">
                        <DeleteParameters>
                            <asp:Parameter Name="original_DocumentID" Type="Int32" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="DocumentName" Type="String" />
                            <asp:Parameter Name="DateInput" Type="DateTime" />
                            <asp:Parameter Name="Comments" Type="String" />
                            <asp:Parameter Name="DocumentCategory" Type="Int32" />
                            <asp:Parameter Name="TopDoc" Type="Boolean" />
                            <asp:Parameter Name="original_DocumentID" Type="Int32" />
                        </UpdateParameters>
                        <InsertParameters>
                            <asp:ControlParameter Name="Comments" Type="String" ControlID="TextBox2" />
                            <asp:ControlParameter Name="DocumentCategory" Type="Int32" ControlID="DropDownList1" PropertyName="SelectedValue" />
                            <asp:ControlParameter Name="TopDoc" Type="Boolean" ControlID="RadioButtonList1" PropertyName="SelectedValue" />
                        </InsertParameters>
                    </asp:SqlDataSource>
                    &nbsp;</p>
            </div> 
                
        </div>
    </asp:Content>

    HTH, Bill Evjen

  • Cool [cool] Re: clubsite whitepaper errors?

    08-13-2005, 9:52 AM
    • Loading...
    • scottt40
    • Joined on 09-05-2002, 2:26 PM
    • CT
    • Posts 165
    Thank you so much for this code...It will make all the difference. I have tried to create the page with modifications for my program, but I have an error on the GridView2 Document Name Hyperlink. Can you show or post the code for that please....Sorry.
    You forgot to make GridView2 - DocumentName a Templated field and show the hyperlink to the file and how to retrieve it...

    Also - Is it possible to store documents outside the web on another physical drive or remote location for security, and what settings on the folder (Files) would we need to set to only allow certain types of documents (.doc, .ppt, .xls and so on)?

    Server Error "Character Not Recognized" occurs when I try to implement the strategy in the Extending Club Site Article...HELP!!!!!
    I already tried to remove the @ symbol?
    <
    ItemTemplate>

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

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

    </ItemTemplate>

    LATER That Day....
    I found two error in the above code:
    1. There are two <%# and %> signs
    2. and you do not need the @ sign, which caused the error..

    IT WORKS NOW

    Thanks Scott
  • Re: clubsite whitepaper errors?

    01-21-2006, 8:17 PM
    • Loading...
    • cdblind
    • Joined on 11-13-2005, 12:53 PM
    • Posts 2

    I was having trouble with this code and found by adding the TypeCode to the DateTime parameter the code worked fine If anyone had sme prob here is what i did.

    SqlDataSource2.InsertParameters.Add("DateInput", TypeCode.DateTime, DateTime.Now.ToString())

  • SQLDataSource2 commands and parameters fixes

    03-06-2006, 6:05 PM
    • Loading...
    • lutz2
    • Joined on 02-10-2006, 2:14 PM
    • Richmond, VA
    • Posts 19

    Bill, thanks for the template and tutorials.

    Testing the code I had a couple problems.

    1) Edits and deletes were failing.  The "originalDocumentID" name in the Commands and Parameters appears to be the problem, so I changed it to "DocumentID", making it consistent with the working code for SQLDataSource1.

    2) Existing UpdateCommand blanks the DocumentName when editing, because DocumentName is a read-only field

    The rewritten SQLDataSource2 section (hopefully the indents are not messed up, last time i posted, the indents in this message designer made a mess):

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
       DeleteCommand="DELETE FROM [Documents] WHERE [DocumentID] = @DocumentID"
       InsertCommand="INSERT INTO [Documents] ([DocumentName], [DateInput], [Comments], [DocumentCategory], [TopDoc]) VALUES (@DocumentName, @DateInput, @Comments, @DocumentCategory, @TopDoc)"
       SelectCommand="SELECT * FROM [Documents]"
       UpdateCommand="UPDATE [Documents] SET [DateInput] = @DateInput, [Comments] = @Comments, [DocumentCategory] = @DocumentCategory, [TopDoc] = @TopDoc WHERE [DocumentID] = @DocumentID">
       <DeleteParameters>
           <asp:Parameter Name="DocumentID" Type="Int32" />
       </DeleteParameters>
       <UpdateParameters>
           <asp:Parameter Name="DateInput" Type="DateTime" />
           <asp:Parameter Name="Comments" Type="String" />
           <asp:Parameter Name="DocumentCategory" Type="Int32" />
           <asp:Parameter Name="TopDoc" Type="Boolean" />
           <asp:Parameter Name="DocumentID" Type="Int32" />
       </UpdateParameters>
       <InsertParameters>
           <asp:ControlParameter Name="Comments" Type="String" ControlID="TextBox2" />
           <asp:ControlParameter Name="DocumentCategory" Type="Int32" ControlID="DropDownList1" PropertyName="SelectedValue" />
           <asp:ControlParameter Name="TopDoc" Type="Boolean" ControlID="RadioButtonList1" PropertyName="SelectedValue" />
           </InsertParameters>
    </asp:SqlDataSource>

     

  • Re: SQLDataSource2 commands and parameters fixes

    03-14-2006, 5:53 PM
    • Loading...
    • DaiBach
    • Joined on 03-14-2006, 9:40 PM
    • Posts 3

    I have always used C and have been using the C# version of the club template.

    Does anyone have code for the button in C#? It is only given in VB above

    Dave

  • Re: SQLDataSource2 commands and parameters fixes

    04-06-2006, 6:55 AM
    • Loading...
    • vedo
    • Joined on 04-06-2006, 10:47 AM
    • Italy
    • Posts 1
    Here the C# versione of the code

    bye
    Riccc


       protected void Button2_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile) {
               
                try {
                    FileUpload1.SaveAs(Server.MapPath("~\\Files\\" + FileUpload1.FileName.ToString()));
                    Label1.Text = "<b>File Successfully Uploaded!</b><br />";
                   
                    SqlDataSource2.DeleteParameters.Add("DeleteDocumentName", FileUpload1.FileName.ToString());
                    SqlDataSource2.Delete();
                                 
                    SqlDataSource2.InsertParameters.Add("DocumentName", FileUpload1.FileName.ToString());
                    SqlDataSource2.InsertParameters.Add("DateInput", TypeCode.DateTime, DateTime.Now.ToString());
                   
                    SqlDataSource2.Insert();
                }
                catch (Exception ex) {
                    Label1.Text = "ERROR IN UPLOADING: " + ex.Message.ToString();
                }
                finally {
                    TextBox2.Text = "";
                }
            }
        }
  • Re: clubsite whitepaper errors?

    07-05-2006, 8:09 PM
    • Loading...
    • JMKCT
    • Joined on 09-23-2005, 3:16 AM
    • Posts 19