This is a migrated thread and some comments may be shown as answers.

Errors

1 Answer 43 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Cécil
Top achievements
Rank 2
Cécil asked on 14 Nov 2008, 02:03 PM
Hi
I am not able compile the project because the following errors:

Name of space for the name or type 'Uploadedfiles' can not be found. Need a using directive or a reference to number of modules (assembly)?
Validation(ASP.Net):Attribute 'LocalizationPath' is not valid attribute of element 'RadUpload'.
Validation(ASP.Net):Attribute 'SkinPath' is not valid attribute of element 'RadUpload'.

the code:

(default.aspx.cs)

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Drawing;
using Telerik.Web;
using Telerik.Web.UI.Upload;
using Telerik;
using Telerik.Charting;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        statusLabel.Text = "";
        errorLabel.Text = "";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {


            if (RadUpload1.UploadedFiles.Count > 0)
            {
                string message = "<br />The following files are upload successfully <br />";
                foreach (UploadedFile file in RadUpload1.UploadedFiles)
                {
                    message += file.GetName() + "<br />";
                    file.SaveAs(@"c:\MyUploadDir\" + file.GetName(), true);
                }
                DisplayMessage(message, false);
            }

            if (RadUpload1.InvalidFiles.Count > 0)
            {
                string error = "<br />The following files are not allowed for upload<br />";
                foreach (UploadedFile ifile in RadUpload1.InvalidFiles)
                {
                    error += ifile.GetName() + "<br />";
                }

                DisplayMessage(error, true);
            }
        }

        catch (Exception ex)
        {
            DisplayMessage("Upload failed" + ex.Message, true);
        }
    }
      
    private void DisplayMessage(string text, bool isError)
        {
            if(isError)
            {
            this.errorLabel.ForeColor = Color.Red;
            this.errorLabel.Text = text;
            }
            else
            {
            this.statusLabel.ForeColor = Color.Green;
            this.statusLabel.Text = text;
            }
        }
   
    protected void RadUpload1_ValidatingFile(object sender, ValidateFileEventArgs e)
    {
        int maxZip = 10485760;//10MB
        int maxText = 4096;//4KB
        int maxJpg = 512000;//500kb

        switch(e.UploadedFile.GetExtension().ToLower())
        {
        case ".zip":
            if (e.UploadedFile.ContentLength>maxZip)
                e.IsValid=false;
            e.SkipInternalValidation=true;
            break;
        case ".txt":
            if(e.UploadedFile.ContentLength>maxText)
                e.IsValid=false;
            e.SkipInternalValidation=true;
            break;
        case ".jpg":
            if(e.UploadedFile.ContentLength>maxJpg)
                e.IsValid=false;
            e.SkipInternalValidation=true;
            break;
        }
    }
}

(default.aspx)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="Telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <table>
        <tr>
        <td>
        
        <Telerik:RadUpload ID="RadUpload1" runat="server" LocalizationPath="RadControls/Upload//Localization" SkinPath="~/RadControls/Upload/Skins" ControlObjectsVisibility="All" TargetFolder="~/MyUploadFiles" OnValidatingFile="RadUpload1_ValidatingFile" MaxFileSize="1024" />
        </td>
        <td align="right">
        <asp:Label ID="statusLabel" runat="server"></asp:Label>
        <asp:Label ID="errorLabel" runat="server"></asp:Label>
        <asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
        </td>
        </tr>
       
        </table>
        
        </div>
    </form>
</body>
</html>

What is the solution?

1 Answer, 1 is accepted

Sort by
0
Accepted
Erjan Gavalji
Telerik team
answered on 14 Nov 2008, 02:54 PM
Hi C├ęcil,

Please, try the following:

(default.aspx.cs)

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Drawing;
using Telerik.Web;
using Telerik.Web.UI;
using Telerik.Web.UI.Upload;
using Telerik;
using Telerik.Charting;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        statusLabel.Text = "";
        errorLabel.Text = "";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {


            if (RadUpload1.UploadedFiles.Count > 0)
            {
                string message = "<br />The following files are upload successfully <br />";
                foreach (UploadedFile file in RadUpload1.UploadedFiles)
                {
                    message += file.GetName() + "<br />";
                    file.SaveAs(@"c:\MyUploadDir\" + file.GetName(), true);
                }
                DisplayMessage(message, false);
            }

            if (RadUpload1.InvalidFiles.Count > 0)
            {
                string error = "<br />The following files are not allowed for upload<br />";
                foreach (UploadedFile ifile in RadUpload1.InvalidFiles)
                {
                    error += ifile.GetName() + "<br />";
                }

                DisplayMessage(error, true);
            }
        }

        catch (Exception ex)
        {
            DisplayMessage("Upload failed" + ex.Message, true);
        }
    }
      
    private void DisplayMessage(string text, bool isError)
        {
            if(isError)
            {
            this.errorLabel.ForeColor = Color.Red;
            this.errorLabel.Text = text;
            }
            else
            {
            this.statusLabel.ForeColor = Color.Green;
            this.statusLabel.Text = text;
            }
        }
   
    protected void RadUpload1_ValidatingFile(object sender, ValidateFileEventArgs e)
    {
        int maxZip = 10485760;//10MB
        int maxText = 4096;//4KB
        int maxJpg = 512000;//500kb

        switch(e.UploadedFile.GetExtension().ToLower())
        {
        case ".zip":
            if (e.UploadedFile.ContentLength>maxZip)
                e.IsValid=false;
            e.SkipInternalValidation=true;
            break;
        case ".txt":
            if(e.UploadedFile.ContentLength>maxText)
                e.IsValid=false;
            e.SkipInternalValidation=true;
            break;
        case ".jpg":
            if(e.UploadedFile.ContentLength>maxJpg)
                e.IsValid=false;
            e.SkipInternalValidation=true;
            break;
        }
    }
}

(default.aspx)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="Telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <table>
        <tr>
        <td>
        
        <Telerik:RadUpload ID="RadUpload1" runat="server" ControlObjectsVisibility="All" TargetFolder="~/MyUploadFiles" OnValidatingFile="RadUpload1_ValidatingFile" MaxFileSize="1024" />
        </td>
        <td align="right">
        <asp:Label ID="statusLabel" runat="server"></asp:Label>
        <asp:Label ID="errorLabel" runat="server"></asp:Label>
        <asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
        </td>
        </tr>
       
        </table>
        
        </div>
    </form>
</body>
</html>


Kind regards,
Erjan Gavalji
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Upload (Obsolete)
Asked by
Cécil
Top achievements
Rank 2
Answers by
Erjan Gavalji
Telerik team
Share this question
or