Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net upload

Posted on 2012-03-29
3
Medium Priority
?
636 Views
Last Modified: 2012-03-30
For some reasons, when upload .pdf is working fine. but when .txt, doc, docx does not do anything....We use ajax 1.0 and framework 2.

Any reasons why and how to fix it?

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UploadNow.ascx.cs" Inherits="UI_UploadNow" %>
<%@ Register Assembly="obout_Interface" Namespace="Obout.Interface" TagPrefix="cc1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>
<%@ Register TagPrefix="obout" Namespace="Obout.ComboBox" Assembly="obout_ComboBox" %>
<style type="text/css">
    .MasterWidth
    {
        width: 930px;
               
    }
</style>
<div id="centeredmenu">        
        <ul>
        <li><a class="active" href="UploadNow.aspx">Upload Outlines Now</a></li>
        </ul>
</div>
<asp:UpdatePanel runat="server">
<ContentTemplate>
        <br /><br />
        <table cellpadding="5" cellspacing="5">
        <tr>
        <td colspan="2">
        <fieldset class="MasterWidth">
        <br />
        <asp:Label ID="StatusLabel" runat="server" Text=""></asp:Label>
        <table>        
        <tr><td>
        <strong>Law School</strong>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator_LawSchool" runat="server"
        ErrorMessage="*" ControlToValidate="TxtSchool01" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
        <br />
        <cc1:OboutTextBox ID="TxtSchool01"
        Width="400" FolderStyle="../Services/UIStyleControls/Obout/Interface/styles/plain/OboutTextBox"
        runat="server" Text=""></cc1:OboutTextBox>
       
        <cc2:AutoCompleteExtender
        runat="server"
        ID="AutoCompleteExtender_SchoolList" ServicePath="~/AutoComplete.asmx"
        ServiceMethod="GetSchoolCompletionList" TargetControlID="TxtSchool01"
        CompletionListCssClass="autocomplete_completionListElement"
        CompletionListItemCssClass="autocomplete_listItem"
        CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
        MinimumPrefixLength="2">
        </cc2:AutoCompleteExtender>
        </td>
        <td><strong>Class</strong>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator_TxtClass01" runat="server"
        ErrorMessage="*" ControlToValidate="TxtClass01" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
        <br />
        <cc1:OboutTextBox FolderStyle="../Services/UIStyleControls/Obout/Interface/styles/plain/OboutTextBox"  ID="TxtClass01" Width="285" runat="server"></cc1:OboutTextBox>
        </td>
        </tr>
        <tr>        
        <td>
        <strong>Professor</strong>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator_TxtProfessor01" runat="server"
        ErrorMessage="*" ControlToValidate="TxtProfessor01" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
        <br />
        <cc1:OboutTextBox FolderStyle="../Services/UIStyleControls/Obout/Interface/styles/plain/OboutTextBox"  ID="TxtProfessor01" Width="285" runat="server"></cc1:OboutTextBox>
        <cc1:OboutTextBox  Visible="false" ID="TxtMajor01" Width="285" runat="server" Text="Law"></cc1:OboutTextBox>
        </td>
        <td>    
        <strong>Textbook</strong>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1_TxtTextbook01" runat="server"
        ErrorMessage="*" ControlToValidate="TxtTextbook01" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
        <br />
        <cc1:OboutTextBox FolderStyle="../Services/UIStyleControls/Obout/Interface/styles/plain/OboutTextBox"  ID="TxtTextbook01" Width="285" runat="server"></cc1:OboutTextBox>
        </td>
        </tr>
        <tr>
        <td><strong>Semester/Quarter</strong>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator_TxtSememter01" runat="server"
        ErrorMessage="*" ControlToValidate="TxtTextbook01" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
        <br />
        <cc1:OboutTextBox FolderStyle="../Services/UIStyleControls/Obout/Interface/styles/plain/OboutTextBox"  ID="TxtSememter01" Width="285" runat="server"></cc1:OboutTextBox>
        </td>
        <td><strong>Year</strong>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1_TxtYear01" runat="server"
        ErrorMessage="*" ControlToValidate="TxtYear01" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
        <br />
        <cc1:OboutTextBox FolderStyle="../Services/UIStyleControls/Obout/Interface/styles/plain/OboutTextBox"  ID="TxtYear01" Width="285" runat="server"></cc1:OboutTextBox>
        </td>
        </tr>
        <tr>
        <td>
        <strong>Total Number of Page</strong>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1_TxtTotalPageNumber01" runat="server"
        ErrorMessage="*" ControlToValidate="TxtTotalPageNumber01" SetFocusOnError="true" Display="Dynamic"></asp:RequiredFieldValidator>
        <br />
        <cc1:OboutTextBox FolderStyle="../Services/UIStyleControls/Obout/Interface/styles/plain/OboutTextBox"  ID="TxtTotalPageNumber01" Width="285" runat="server"></cc1:OboutTextBox>        
        </td>
        <td>
        <strong>Upload files</strong><br />
        <asp:FileUpload  CssClass="" id="FileUploadControl" runat="server" />&nbsp;
        </td>
        </tr>
        <tr>
        <td><br /></td>
        <td>
        <cc1:OboutButton
        FolderStyle="../Services/UIStyleControls/Obout/Interface/styles/plain/OboutButton"
        ID="UploadButton"  
        Text="Upload Now"
        ToolTip="Upload Now"
        onclick="UploadButton_Click"
        runat="server"></cc1:OboutButton>
        </td>
        </tr>
        </table>  
        </fieldset>
        </td>
        </tr>
        </table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UploadButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SdsCollegeList" runat="server"
    ConnectionString="<%$ ConnectionStrings:OutlinesDatabaseConnection %>"
    SelectCommand="SELECT [SchoolName], [SchoolId], [CollegeId] FROM [Schools] WHERE ([StatusId] = @StatusId) And (SchoolName <> '')">
    <SelectParameters>
        <asp:Parameter DefaultValue="1" Name="StatusId" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

//Code Behind

    protected void UploadButton_Click(object sender, EventArgs e)
    {
        if (FileUploadControl.HasFile == true)
        {
            string FileExt = System.IO.Path.GetExtension(FileUploadControl.FileName);
            string UploadToLocation = ConfigurationManager.AppSettings["UploadToLocation"];
            if ((FileExt == ".pdf"))
            {
                //Step 1: Upload To the Server
                StatusLabel.Visible = true;
                //"C:\\HostingSpaces\\admin1\\kemkoaerospace.com\\wwwroot\\Aviation\\AdminZone\\"
                //FileUploadControl.SaveAs(UploadToLocation + FileUploadControl.FileName);
                FileUploadControl.PostedFile.SaveAs(@"C:\test\" + System.IO.Path.GetFileName(FileUploadControl.PostedFile.FileName));
                //StatusLabel.Text = "File Name: " + FileUploadControl.PostedFile.FileName + "<br>" +
                //FileUploadControl.PostedFile.ContentLength + "<br>" +
                //FileUploadControl.PostedFile.ToString() + "<br>" +
                //FileUploadControl.PostedFile.ContentType + "<br>";
                StatusLabel.Text = "Thank you. You successfully uploaded an outline.";
                //===============================================
                //Step 2: Save the transaction into the database
                //===============================================
                //Step 3: Email to the site owner - from user to owner
                  }
            else
            {
                StatusLabel.Text = "Invalid Extension!";
                StatusLabel.Visible = true;
            }
        }
    }
0
Comment
Question by:Webboy2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 37784321
Looking at code behind you are trying to upload only files with .pdf ext and for rest of the files you are trying to throw error message. There is an if statement in there which is trying to equate it to .pdf.  

Let me know if I misunderstood your question.
0
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 37784331
Pretty-much what Luck85 said. Do this:
Change:
 if ((FileExt == ".pdf"))

to

if ( !string.IsNullOrEmpty( FileExt ) )
0
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 2000 total points
ID: 37785438
In agreement to both above comments by expert, I would like to add code line for .txt, doc, docx files:

if ((FileExt == ".pdf" || FileExt==".txt" || FileExt==".doc" || FileExt==".docx"))
            {
                //Step 1: Upload To the Server
                StatusLabel.Visible = true;

Open in new window


Now when you try to upload other extension files (as allowed in code), they all would get uploaded.
0

Featured Post

URL rewriting in AWS CloudFront

A quick how-to guide to implement with a Lambda function!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question