<INPUT = 'File'> upload problem

B

Brian Henry

Hi, I am having a problem with an attachment system I made... it works with
files up to ~3MB in size then after that if you try to upload a file it just
goes to a "Page can not be displayed" page like it tried to do it but
errored... I thought changeing the max size for the file input box to about
100mb would fix it but nope

here is my page code and my code behind code...

==[html page]=============

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Attachments.aspx.vb" Inherits="SecureEmail.Attachments"%>
<%@ Register TagPrefix="cc1" Namespace="SecureEmail" Assembly="SecureEmail"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlTop" Src="../Themes/ctrlTop.ascx"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlBottom"
Src="../Themes/ctrlBottom.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlLeftSide"
Src="../Themes/ctrlLeftSide.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlRightSide"
Src="../Themes/ctrlRightSide.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Reschini Secure E-Mail Network</title>
<meta content="SharePoint.WebPartPage.Document" name="ProgId">
<meta content="full" name="WebPartPageExpansion">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"
MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table id="table1" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrltop id="CtrlTop1"
runat="server"></uc1:ctrltop></td>
</tr>
<tr>
<td vAlign="top" height="100%">
<table id="table2" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrlleftside id="CtrlLeftSide1"
runat="server"></uc1:ctrlleftside></td>
<td vAlign="top" width="100%">
<TABLE id="table4" cellSpacing="0" cellPadding="0" width="100%"
bgColor="#a0c6e5" border="0"
class="toolbar">
<TR>
<TD>
<p align="left"><asp:button id="btnOK" runat="server" Text="OK"
Font-Size="8pt"></asp:button>&nbsp;<asp:button id="btnAddAttachment"
runat="server" Text="Add Attachment" Font-Size="8pt"></asp:button></p>
</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>
<table border="0" width="100%" id="table6" cellspacing="0"
cellpadding="0">
<tr>
<td>
<cc1:ctrlPageHeaderBox id="ctrlPageHeaderBox" runat="server"
Font-Size="8pt" AutoPostBack="True"
Text="Attachments"></cc1:ctrlPageHeaderBox></td>
</tr>
</table>
<table id="table3" cellPadding="0" width="100%" border="0">
<TBODY>
<tr>
<td><FONT face="Arial" size="1">Brows for an attachment using
the browse button, then
click add attachment to add it to the attachments
list.</FONT></td>
</tr>
<tr>
<td>&nbsp;<INPUT id="fileIn" type="file" name="fileIn"
runat="server">
<asp:Label id="lblErrorMsg" runat="server" Font-Size="8pt"
Font-Names="verdana" ForeColor="Red"></asp:Label>
<asp:customvalidator id="cvFile" runat="server" Font-Size="8pt"
ErrorMessage="Must specify a file"
Font-Names="Verdana"></asp:customvalidator></td>
</tr>
<tr>
<td>&nbsp;<FONT face="Arial" size="1">Current Attachments For
Message:</FONT></td>
</tr>
<tr>
<td><asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="0" width="350" id="table5" cellspacing="0"
cellpadding="5" style="border: 1px solid #A0C6E5">
<tr>
<td bgcolor="#A0C6E5" width="100%">
<font face="Arial" style="font-size:
8pt">Attachments</font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Size</span></font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Delete</span></font></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="100%" align="left">
<font size="2" face="Arial"><img border="0"
src="../images/attachfile.gif" width="17" height="13">
<%# DataBinder.Eval(Container.DataItem,"FileName")%>
</font>
</td>
<td nowrap align="right">
<font face="Arial" style="font-size: 8pt">
<%#
SecureEmail.Functions.FormatFileSize(DataBinder.Eval(Container.DataItem,"Fil
eSize"))%>
</font>
</td>
<td nowrap align="center">
<a href='attachments.aspx?action=remove&id=<%#
DataBinder.Eval(Container.dataitem,"ID")%>'>
<img border="0" src="../images/delete.gif" width="16"
height="16"></a></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td width="100%" align="left" style="border-top: 1px solid
#A0C6E5">
<p align="right">
<font face="Arial" style="font-size: 8pt">Total</font>
</td>
<td nowrap align="right" style="border-top: 1px solid
#A0C6E5">
<font face="Arial" style="font-size: 8pt">0.05
MB</font></td>
<td nowrap align="center" style="border-top: 1px solid
#A0C6E5">&nbsp;</td>
</tr>
</table>
</FooterTemplate> </asp:repeater></td>
</tr>
</table>
<p>&nbsp;</p>
</td>
<td vAlign="top"><uc1:ctrlrightside id="CtrlRightSide1"
runat="server"></uc1:ctrlrightside></td>
</tr>
</table>
</TD></TR>
<tr>
<td vAlign="top"><uc1:ctrlbottom id="CtrlBottom1"
runat="server"></uc1:ctrlbottom></td>
</tr>
</TBODY></TABLE></form>
</body>
</HTML>




============================================================================
=====
==== Code Behind ===========================================================


Public Class Attachments

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents btnOK As System.Web.UI.WebControls.Button

Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater

Protected WithEvents fileIn As System.Web.UI.HtmlControls.HtmlInputFile

Protected WithEvents btnAddAttachment As System.Web.UI.WebControls.Button

Protected WithEvents cvFile As System.Web.UI.WebControls.CustomValidator

Protected WithEvents ctrlPageHeaderBox As SecureEmail.ctrlPageHeaderBox

Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

' if there isn't an attachments table already...

If Session("AttachmentsTable") Is Nothing Then

' get schema from db and create a table from it...

Dim dt_attachments As New DataTable

dt_attachments.Columns.Add(New DataColumn("FileName", GetType(String)))

dt_attachments.Columns.Add(New DataColumn("FileSize", GetType(Int32)))

Dim dc_ID As DataColumn = dt_attachments.Columns.Add("ID", GetType(Integer))

dc_ID.AutoIncrement = True

dc_ID.AutoIncrementSeed = 1

dc_ID.AutoIncrementStep = 2

dc_ID.ReadOnly = True

dt_attachments.PrimaryKey = New DataColumn() {dt_attachments.Columns("ID")}

dt_attachments.Columns.Add(New DataColumn("AttachmentData",
GetType(Byte())))

Session("AttachmentsTable") = dt_attachments

End If

If Not Request.QueryString("action") Is Nothing Then

Select Case Request.QueryString("action").ToLower

Case "remove"

Dim DR_ROW As DataRow

DR_ROW = DirectCast(Session("AttachmentsTable"),
DataTable).Rows.Find(Convert.ToInt32(Request.QueryString("ID")))

DR_ROW.Delete()



End Select

End If

End If

Me.Repeater1.DataSource = Session("AttachmentsTable")

Me.Repeater1.DataBind()

End Sub





Private Sub AddAttachment()

If Me.fileIn.Value.Trim.Length = 0 Then

Me.cvFile.IsValid = False

Else

Try

Me.lblErrorMsg.Visible = False

Dim AttachedFileCollection As HttpFileCollection

Dim a As HtmlInputFile

Me.fileIn.MaxLength = (100 * 1024) ' 100 MB upload max

Dim MyFile As HttpPostedFile

Dim FileLength As Integer

Dim FileName As String

Dim FileStream As System.IO.Stream

AttachedFileCollection = Request.Files

MyFile = AttachedFileCollection(0)

FileLength = MyFile.ContentLength

Dim FileData(FileLength) As Byte





FileStream = MyFile.InputStream

FileStream.Read(FileData, 0, FileLength)





Me.cvFile.IsValid = True

Dim dr_row As DataRow = DirectCast(Session("AttachmentsTable"),
DataTable).NewRow

dr_row("FileName") = IO.Path.GetFileName(MyFile.FileName).ToUpper

dr_row("FileSize") = MyFile.ContentLength

dr_row("AttachmentData") = FileData

DirectCast(Session("AttachmentsTable"), DataTable).Rows.Add(dr_row)

Catch ex As Exception

Me.lblErrorMsg.Visible = True

Me.lblErrorMsg.Text = "Error uploading file: " & ex.Message

End Try

Me.Repeater1.DataBind()

End If

End Sub

Private Sub btnAddAttachment_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddAttachment.Click

AddAttachment()

End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click

Response.Redirect("Compose.aspx")

End Sub

End Class
 
B

Brian Henry

this happens instantaniously... soon as i click on the attach button, it
goes straight to the page can not be displayed page... where can i look at
time out settings though?


Mark said:
Have you checked to see if the page is timing out before the upload is
complete?

--
----------------------------------------------------------------
-**-
www.byteboss.com : EZ website builder
-**-
Replace the Z with the e to reply
----------------------------------------------------------------

Brian Henry said:
Hi, I am having a problem with an attachment system I made... it works with
files up to ~3MB in size then after that if you try to upload a file it just
goes to a "Page can not be displayed" page like it tried to do it but
errored... I thought changeing the max size for the file input box to about
100mb would fix it but nope

here is my page code and my code behind code...

==[html page]=============

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Attachments.aspx.vb" Inherits="SecureEmail.Attachments"%>
<%@ Register TagPrefix="cc1" Namespace="SecureEmail" Assembly="SecureEmail"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlTop" Src="../Themes/ctrlTop.ascx"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlBottom"
Src="../Themes/ctrlBottom.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlLeftSide"
Src="../Themes/ctrlLeftSide.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlRightSide"
Src="../Themes/ctrlRightSide.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Reschini Secure E-Mail Network</title>
<meta content="SharePoint.WebPartPage.Document" name="ProgId">
<meta content="full" name="WebPartPageExpansion">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"
MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table id="table1" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrltop id="CtrlTop1"
runat="server"></uc1:ctrltop></td>
</tr>
<tr>
<td vAlign="top" height="100%">
<table id="table2" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrlleftside id="CtrlLeftSide1"
runat="server"></uc1:ctrlleftside></td>
<td vAlign="top" width="100%">
<TABLE id="table4" cellSpacing="0" cellPadding="0" width="100%"
bgColor="#a0c6e5" border="0"
class="toolbar">
<TR>
<TD>
<p align="left"><asp:button id="btnOK" runat="server" Text="OK"
Font-Size="8pt"></asp:button>&nbsp;<asp:button id="btnAddAttachment"
runat="server" Text="Add Attachment" Font-Size="8pt"></asp:button></p>
</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>
<table border="0" width="100%" id="table6" cellspacing="0"
cellpadding="0">
<tr>
<td>
<cc1:ctrlPageHeaderBox id="ctrlPageHeaderBox" runat="server"
Font-Size="8pt" AutoPostBack="True"
Text="Attachments"></cc1:ctrlPageHeaderBox></td>
</tr>
</table>
<table id="table3" cellPadding="0" width="100%" border="0">
<TBODY>
<tr>
<td><FONT face="Arial" size="1">Brows for an attachment using
the browse button, then
click add attachment to add it to the attachments
list.</FONT></td>
</tr>
<tr>
<td>&nbsp;<INPUT id="fileIn" type="file" name="fileIn"
runat="server">
<asp:Label id="lblErrorMsg" runat="server" Font-Size="8pt"
Font-Names="verdana" ForeColor="Red"></asp:Label>
<asp:customvalidator id="cvFile" runat="server" Font-Size="8pt"
ErrorMessage="Must specify a file"
Font-Names="Verdana"></asp:customvalidator></td>
</tr>
<tr>
<td>&nbsp;<FONT face="Arial" size="1">Current Attachments For
Message:</FONT></td>
</tr>
<tr>
<td><asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="0" width="350" id="table5" cellspacing="0"
cellpadding="5" style="border: 1px solid #A0C6E5">
<tr>
<td bgcolor="#A0C6E5" width="100%">
<font face="Arial" style="font-size:
8pt">Attachments</font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Size</span></font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Delete</span></font></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="100%" align="left">
<font size="2" face="Arial"><img border="0"
src="../images/attachfile.gif" width="17" height="13">
<%# DataBinder.Eval(Container.DataItem,"FileName")%>
</font>
</td>
<td nowrap align="right">
<font face="Arial" style="font-size: 8pt">
<%#
SecureEmail.Functions.FormatFileSize(DataBinder.Eval(Container.DataItem,"Fil
eSize"))%>
</font>
</td>
<td nowrap align="center">
<a href='attachments.aspx?action=remove&id=<%#
DataBinder.Eval(Container.dataitem,"ID")%>'>
<img border="0" src="../images/delete.gif" width="16"
height="16"></a></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td width="100%" align="left" style="border-top: 1px solid
#A0C6E5">
<p align="right">
<font face="Arial" style="font-size: 8pt">Total</font>
</td>
<td nowrap align="right" style="border-top: 1px solid
#A0C6E5">
<font face="Arial" style="font-size: 8pt">0.05
MB</font></td>
<td nowrap align="center" style="border-top: 1px solid
#A0C6E5">&nbsp;</td>
</tr>
</table>
</FooterTemplate> </asp:repeater></td>
</tr>
</table>
<p>&nbsp;</p>
</td>
<td vAlign="top"><uc1:ctrlrightside id="CtrlRightSide1"
runat="server"></uc1:ctrlrightside></td>
</tr>
</table>
</TD></TR>
<tr>
<td vAlign="top"><uc1:ctrlbottom id="CtrlBottom1"
runat="server"></uc1:ctrlbottom></td>
</tr>
</TBODY></TABLE></form>
</body>
</HTML>
============================================================================
=====
==== Code Behind ===========================================================


Public Class Attachments

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents btnOK As System.Web.UI.WebControls.Button

Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater

Protected WithEvents fileIn As System.Web.UI.HtmlControls.HtmlInputFile

Protected WithEvents btnAddAttachment As System.Web.UI.WebControls.Button

Protected WithEvents cvFile As System.Web.UI.WebControls.CustomValidator

Protected WithEvents ctrlPageHeaderBox As SecureEmail.ctrlPageHeaderBox

Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

' if there isn't an attachments table already...

If Session("AttachmentsTable") Is Nothing Then

' get schema from db and create a table from it...

Dim dt_attachments As New DataTable

dt_attachments.Columns.Add(New DataColumn("FileName", GetType(String)))

dt_attachments.Columns.Add(New DataColumn("FileSize", GetType(Int32)))

Dim dc_ID As DataColumn = dt_attachments.Columns.Add("ID", GetType(Integer))

dc_ID.AutoIncrement = True

dc_ID.AutoIncrementSeed = 1

dc_ID.AutoIncrementStep = 2

dc_ID.ReadOnly = True

dt_attachments.PrimaryKey = New DataColumn() {dt_attachments.Columns("ID")}

dt_attachments.Columns.Add(New DataColumn("AttachmentData",
GetType(Byte())))

Session("AttachmentsTable") = dt_attachments

End If

If Not Request.QueryString("action") Is Nothing Then

Select Case Request.QueryString("action").ToLower

Case "remove"

Dim DR_ROW As DataRow

DR_ROW = DirectCast(Session("AttachmentsTable"),
DataTable).Rows.Find(Convert.ToInt32(Request.QueryString("ID")))

DR_ROW.Delete()



End Select

End If

End If

Me.Repeater1.DataSource = Session("AttachmentsTable")

Me.Repeater1.DataBind()

End Sub





Private Sub AddAttachment()

If Me.fileIn.Value.Trim.Length = 0 Then

Me.cvFile.IsValid = False

Else

Try

Me.lblErrorMsg.Visible = False

Dim AttachedFileCollection As HttpFileCollection

Dim a As HtmlInputFile

Me.fileIn.MaxLength = (100 * 1024) ' 100 MB upload max

Dim MyFile As HttpPostedFile

Dim FileLength As Integer

Dim FileName As String

Dim FileStream As System.IO.Stream

AttachedFileCollection = Request.Files

MyFile = AttachedFileCollection(0)

FileLength = MyFile.ContentLength

Dim FileData(FileLength) As Byte





FileStream = MyFile.InputStream

FileStream.Read(FileData, 0, FileLength)





Me.cvFile.IsValid = True

Dim dr_row As DataRow = DirectCast(Session("AttachmentsTable"),
DataTable).NewRow

dr_row("FileName") = IO.Path.GetFileName(MyFile.FileName).ToUpper

dr_row("FileSize") = MyFile.ContentLength

dr_row("AttachmentData") = FileData

DirectCast(Session("AttachmentsTable"), DataTable).Rows.Add(dr_row)

Catch ex As Exception

Me.lblErrorMsg.Visible = True

Me.lblErrorMsg.Text = "Error uploading file: " & ex.Message

End Try

Me.Repeater1.DataBind()

End If

End Sub

Private Sub btnAddAttachment_Click(ByVal sender As System.Object, ByVal
e
As
System.EventArgs) Handles btnAddAttachment.Click

AddAttachment()

End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click

Response.Redirect("Compose.aspx")

End Sub

End Class
 
C

Chris Simmons

Hi, I am having a problem with an attachment system I made... it works with
files up to ~3MB in size then after that if you try to upload a file it just
goes to a "Page can not be displayed" page like it tried to do it but
errored... I thought changeing the max size for the file input box to about
100mb would fix it but nope

here is my page code and my code behind code...

Try this first:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626

"~3MB" is close enough to 4MB, the default limit.
 
M

Mark

Have you checked to see if the page is timing out before the upload is
complete?

--
----------------------------------------------------------------
-**-
www.byteboss.com : EZ website builder
-**-
Replace the Z with the e to reply
----------------------------------------------------------------

Brian Henry said:
Hi, I am having a problem with an attachment system I made... it works with
files up to ~3MB in size then after that if you try to upload a file it just
goes to a "Page can not be displayed" page like it tried to do it but
errored... I thought changeing the max size for the file input box to about
100mb would fix it but nope

here is my page code and my code behind code...

==[html page]=============

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Attachments.aspx.vb" Inherits="SecureEmail.Attachments"%>
<%@ Register TagPrefix="cc1" Namespace="SecureEmail" Assembly="SecureEmail"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlTop" Src="../Themes/ctrlTop.ascx"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlBottom"
Src="../Themes/ctrlBottom.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlLeftSide"
Src="../Themes/ctrlLeftSide.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlRightSide"
Src="../Themes/ctrlRightSide.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Reschini Secure E-Mail Network</title>
<meta content="SharePoint.WebPartPage.Document" name="ProgId">
<meta content="full" name="WebPartPageExpansion">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"
MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table id="table1" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrltop id="CtrlTop1"
runat="server"></uc1:ctrltop></td>
</tr>
<tr>
<td vAlign="top" height="100%">
<table id="table2" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrlleftside id="CtrlLeftSide1"
runat="server"></uc1:ctrlleftside></td>
<td vAlign="top" width="100%">
<TABLE id="table4" cellSpacing="0" cellPadding="0" width="100%"
bgColor="#a0c6e5" border="0"
class="toolbar">
<TR>
<TD>
<p align="left"><asp:button id="btnOK" runat="server" Text="OK"
Font-Size="8pt"></asp:button>&nbsp;<asp:button id="btnAddAttachment"
runat="server" Text="Add Attachment" Font-Size="8pt"></asp:button></p>
</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>
<table border="0" width="100%" id="table6" cellspacing="0"
cellpadding="0">
<tr>
<td>
<cc1:ctrlPageHeaderBox id="ctrlPageHeaderBox" runat="server"
Font-Size="8pt" AutoPostBack="True"
Text="Attachments"></cc1:ctrlPageHeaderBox></td>
</tr>
</table>
<table id="table3" cellPadding="0" width="100%" border="0">
<TBODY>
<tr>
<td><FONT face="Arial" size="1">Brows for an attachment using
the browse button, then
click add attachment to add it to the attachments
list.</FONT></td>
</tr>
<tr>
<td>&nbsp;<INPUT id="fileIn" type="file" name="fileIn"
runat="server">
<asp:Label id="lblErrorMsg" runat="server" Font-Size="8pt"
Font-Names="verdana" ForeColor="Red"></asp:Label>
<asp:customvalidator id="cvFile" runat="server" Font-Size="8pt"
ErrorMessage="Must specify a file"
Font-Names="Verdana"></asp:customvalidator></td>
</tr>
<tr>
<td>&nbsp;<FONT face="Arial" size="1">Current Attachments For
Message:</FONT></td>
</tr>
<tr>
<td><asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="0" width="350" id="table5" cellspacing="0"
cellpadding="5" style="border: 1px solid #A0C6E5">
<tr>
<td bgcolor="#A0C6E5" width="100%">
<font face="Arial" style="font-size:
8pt">Attachments</font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Size</span></font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Delete</span></font></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="100%" align="left">
<font size="2" face="Arial"><img border="0"
src="../images/attachfile.gif" width="17" height="13">
<%# DataBinder.Eval(Container.DataItem,"FileName")%>
</font>
</td>
<td nowrap align="right">
<font face="Arial" style="font-size: 8pt">
<%#
SecureEmail.Functions.FormatFileSize(DataBinder.Eval(Container.DataItem,"Fil
eSize"))%>
</font>
</td>
<td nowrap align="center">
<a href='attachments.aspx?action=remove&id=<%#
DataBinder.Eval(Container.dataitem,"ID")%>'>
<img border="0" src="../images/delete.gif" width="16"
height="16"></a></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td width="100%" align="left" style="border-top: 1px solid
#A0C6E5">
<p align="right">
<font face="Arial" style="font-size: 8pt">Total</font>
</td>
<td nowrap align="right" style="border-top: 1px solid
#A0C6E5">
<font face="Arial" style="font-size: 8pt">0.05
MB</font></td>
<td nowrap align="center" style="border-top: 1px solid
#A0C6E5">&nbsp;</td>
</tr>
</table>
</FooterTemplate> </asp:repeater></td>
</tr>
</table>
<p>&nbsp;</p>
</td>
<td vAlign="top"><uc1:ctrlrightside id="CtrlRightSide1"
runat="server"></uc1:ctrlrightside></td>
</tr>
</table>
</TD></TR>
<tr>
<td vAlign="top"><uc1:ctrlbottom id="CtrlBottom1"
runat="server"></uc1:ctrlbottom></td>
</tr>
</TBODY></TABLE></form>
</body>
</HTML>




============================================================================
=====
==== Code Behind ===========================================================


Public Class Attachments

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents btnOK As System.Web.UI.WebControls.Button

Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater

Protected WithEvents fileIn As System.Web.UI.HtmlControls.HtmlInputFile

Protected WithEvents btnAddAttachment As System.Web.UI.WebControls.Button

Protected WithEvents cvFile As System.Web.UI.WebControls.CustomValidator

Protected WithEvents ctrlPageHeaderBox As SecureEmail.ctrlPageHeaderBox

Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

' if there isn't an attachments table already...

If Session("AttachmentsTable") Is Nothing Then

' get schema from db and create a table from it...

Dim dt_attachments As New DataTable

dt_attachments.Columns.Add(New DataColumn("FileName", GetType(String)))

dt_attachments.Columns.Add(New DataColumn("FileSize", GetType(Int32)))

Dim dc_ID As DataColumn = dt_attachments.Columns.Add("ID", GetType(Integer))

dc_ID.AutoIncrement = True

dc_ID.AutoIncrementSeed = 1

dc_ID.AutoIncrementStep = 2

dc_ID.ReadOnly = True

dt_attachments.PrimaryKey = New DataColumn() {dt_attachments.Columns("ID")}

dt_attachments.Columns.Add(New DataColumn("AttachmentData",
GetType(Byte())))

Session("AttachmentsTable") = dt_attachments

End If

If Not Request.QueryString("action") Is Nothing Then

Select Case Request.QueryString("action").ToLower

Case "remove"

Dim DR_ROW As DataRow

DR_ROW = DirectCast(Session("AttachmentsTable"),
DataTable).Rows.Find(Convert.ToInt32(Request.QueryString("ID")))

DR_ROW.Delete()



End Select

End If

End If

Me.Repeater1.DataSource = Session("AttachmentsTable")

Me.Repeater1.DataBind()

End Sub





Private Sub AddAttachment()

If Me.fileIn.Value.Trim.Length = 0 Then

Me.cvFile.IsValid = False

Else

Try

Me.lblErrorMsg.Visible = False

Dim AttachedFileCollection As HttpFileCollection

Dim a As HtmlInputFile

Me.fileIn.MaxLength = (100 * 1024) ' 100 MB upload max

Dim MyFile As HttpPostedFile

Dim FileLength As Integer

Dim FileName As String

Dim FileStream As System.IO.Stream

AttachedFileCollection = Request.Files

MyFile = AttachedFileCollection(0)

FileLength = MyFile.ContentLength

Dim FileData(FileLength) As Byte





FileStream = MyFile.InputStream

FileStream.Read(FileData, 0, FileLength)





Me.cvFile.IsValid = True

Dim dr_row As DataRow = DirectCast(Session("AttachmentsTable"),
DataTable).NewRow

dr_row("FileName") = IO.Path.GetFileName(MyFile.FileName).ToUpper

dr_row("FileSize") = MyFile.ContentLength

dr_row("AttachmentData") = FileData

DirectCast(Session("AttachmentsTable"), DataTable).Rows.Add(dr_row)

Catch ex As Exception

Me.lblErrorMsg.Visible = True

Me.lblErrorMsg.Text = "Error uploading file: " & ex.Message

End Try

Me.Repeater1.DataBind()

End If

End Sub

Private Sub btnAddAttachment_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddAttachment.Click

AddAttachment()

End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click

Response.Redirect("Compose.aspx")

End Sub

End Class
 
S

Steve C. Orr [MVP, MCSD]

You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Brian Henry said:
Hi, I am having a problem with an attachment system I made... it works with
files up to ~3MB in size then after that if you try to upload a file it just
goes to a "Page can not be displayed" page like it tried to do it but
errored... I thought changeing the max size for the file input box to about
100mb would fix it but nope

here is my page code and my code behind code...

==[html page]=============

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Attachments.aspx.vb" Inherits="SecureEmail.Attachments"%>
<%@ Register TagPrefix="cc1" Namespace="SecureEmail" Assembly="SecureEmail"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlTop" Src="../Themes/ctrlTop.ascx"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlBottom"
Src="../Themes/ctrlBottom.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlLeftSide"
Src="../Themes/ctrlLeftSide.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlRightSide"
Src="../Themes/ctrlRightSide.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Reschini Secure E-Mail Network</title>
<meta content="SharePoint.WebPartPage.Document" name="ProgId">
<meta content="full" name="WebPartPageExpansion">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"
MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table id="table1" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrltop id="CtrlTop1"
runat="server"></uc1:ctrltop></td>
</tr>
<tr>
<td vAlign="top" height="100%">
<table id="table2" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrlleftside id="CtrlLeftSide1"
runat="server"></uc1:ctrlleftside></td>
<td vAlign="top" width="100%">
<TABLE id="table4" cellSpacing="0" cellPadding="0" width="100%"
bgColor="#a0c6e5" border="0"
class="toolbar">
<TR>
<TD>
<p align="left"><asp:button id="btnOK" runat="server" Text="OK"
Font-Size="8pt"></asp:button>&nbsp;<asp:button id="btnAddAttachment"
runat="server" Text="Add Attachment" Font-Size="8pt"></asp:button></p>
</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>
<table border="0" width="100%" id="table6" cellspacing="0"
cellpadding="0">
<tr>
<td>
<cc1:ctrlPageHeaderBox id="ctrlPageHeaderBox" runat="server"
Font-Size="8pt" AutoPostBack="True"
Text="Attachments"></cc1:ctrlPageHeaderBox></td>
</tr>
</table>
<table id="table3" cellPadding="0" width="100%" border="0">
<TBODY>
<tr>
<td><FONT face="Arial" size="1">Brows for an attachment using
the browse button, then
click add attachment to add it to the attachments
list.</FONT></td>
</tr>
<tr>
<td>&nbsp;<INPUT id="fileIn" type="file" name="fileIn"
runat="server">
<asp:Label id="lblErrorMsg" runat="server" Font-Size="8pt"
Font-Names="verdana" ForeColor="Red"></asp:Label>
<asp:customvalidator id="cvFile" runat="server" Font-Size="8pt"
ErrorMessage="Must specify a file"
Font-Names="Verdana"></asp:customvalidator></td>
</tr>
<tr>
<td>&nbsp;<FONT face="Arial" size="1">Current Attachments For
Message:</FONT></td>
</tr>
<tr>
<td><asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="0" width="350" id="table5" cellspacing="0"
cellpadding="5" style="border: 1px solid #A0C6E5">
<tr>
<td bgcolor="#A0C6E5" width="100%">
<font face="Arial" style="font-size:
8pt">Attachments</font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Size</span></font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Delete</span></font></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="100%" align="left">
<font size="2" face="Arial"><img border="0"
src="../images/attachfile.gif" width="17" height="13">
<%# DataBinder.Eval(Container.DataItem,"FileName")%>
</font>
</td>
<td nowrap align="right">
<font face="Arial" style="font-size: 8pt">
<%#
SecureEmail.Functions.FormatFileSize(DataBinder.Eval(Container.DataItem,"Fil
eSize"))%>
</font>
</td>
<td nowrap align="center">
<a href='attachments.aspx?action=remove&id=<%#
DataBinder.Eval(Container.dataitem,"ID")%>'>
<img border="0" src="../images/delete.gif" width="16"
height="16"></a></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td width="100%" align="left" style="border-top: 1px solid
#A0C6E5">
<p align="right">
<font face="Arial" style="font-size: 8pt">Total</font>
</td>
<td nowrap align="right" style="border-top: 1px solid
#A0C6E5">
<font face="Arial" style="font-size: 8pt">0.05
MB</font></td>
<td nowrap align="center" style="border-top: 1px solid
#A0C6E5">&nbsp;</td>
</tr>
</table>
</FooterTemplate> </asp:repeater></td>
</tr>
</table>
<p>&nbsp;</p>
</td>
<td vAlign="top"><uc1:ctrlrightside id="CtrlRightSide1"
runat="server"></uc1:ctrlrightside></td>
</tr>
</table>
</TD></TR>
<tr>
<td vAlign="top"><uc1:ctrlbottom id="CtrlBottom1"
runat="server"></uc1:ctrlbottom></td>
</tr>
</TBODY></TABLE></form>
</body>
</HTML>




============================================================================
=====
==== Code Behind ===========================================================


Public Class Attachments

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents btnOK As System.Web.UI.WebControls.Button

Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater

Protected WithEvents fileIn As System.Web.UI.HtmlControls.HtmlInputFile

Protected WithEvents btnAddAttachment As System.Web.UI.WebControls.Button

Protected WithEvents cvFile As System.Web.UI.WebControls.CustomValidator

Protected WithEvents ctrlPageHeaderBox As SecureEmail.ctrlPageHeaderBox

Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

' if there isn't an attachments table already...

If Session("AttachmentsTable") Is Nothing Then

' get schema from db and create a table from it...

Dim dt_attachments As New DataTable

dt_attachments.Columns.Add(New DataColumn("FileName", GetType(String)))

dt_attachments.Columns.Add(New DataColumn("FileSize", GetType(Int32)))

Dim dc_ID As DataColumn = dt_attachments.Columns.Add("ID", GetType(Integer))

dc_ID.AutoIncrement = True

dc_ID.AutoIncrementSeed = 1

dc_ID.AutoIncrementStep = 2

dc_ID.ReadOnly = True

dt_attachments.PrimaryKey = New DataColumn() {dt_attachments.Columns("ID")}

dt_attachments.Columns.Add(New DataColumn("AttachmentData",
GetType(Byte())))

Session("AttachmentsTable") = dt_attachments

End If

If Not Request.QueryString("action") Is Nothing Then

Select Case Request.QueryString("action").ToLower

Case "remove"

Dim DR_ROW As DataRow

DR_ROW = DirectCast(Session("AttachmentsTable"),
DataTable).Rows.Find(Convert.ToInt32(Request.QueryString("ID")))

DR_ROW.Delete()



End Select

End If

End If

Me.Repeater1.DataSource = Session("AttachmentsTable")

Me.Repeater1.DataBind()

End Sub





Private Sub AddAttachment()

If Me.fileIn.Value.Trim.Length = 0 Then

Me.cvFile.IsValid = False

Else

Try

Me.lblErrorMsg.Visible = False

Dim AttachedFileCollection As HttpFileCollection

Dim a As HtmlInputFile

Me.fileIn.MaxLength = (100 * 1024) ' 100 MB upload max

Dim MyFile As HttpPostedFile

Dim FileLength As Integer

Dim FileName As String

Dim FileStream As System.IO.Stream

AttachedFileCollection = Request.Files

MyFile = AttachedFileCollection(0)

FileLength = MyFile.ContentLength

Dim FileData(FileLength) As Byte





FileStream = MyFile.InputStream

FileStream.Read(FileData, 0, FileLength)





Me.cvFile.IsValid = True

Dim dr_row As DataRow = DirectCast(Session("AttachmentsTable"),
DataTable).NewRow

dr_row("FileName") = IO.Path.GetFileName(MyFile.FileName).ToUpper

dr_row("FileSize") = MyFile.ContentLength

dr_row("AttachmentData") = FileData

DirectCast(Session("AttachmentsTable"), DataTable).Rows.Add(dr_row)

Catch ex As Exception

Me.lblErrorMsg.Visible = True

Me.lblErrorMsg.Text = "Error uploading file: " & ex.Message

End Try

Me.Repeater1.DataBind()

End If

End Sub

Private Sub btnAddAttachment_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddAttachment.Click

AddAttachment()

End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click

Response.Redirect("Compose.aspx")

End Sub

End Class
 
S

Steven Cheng[MSFT]

Hi Brian,

I've noticed that there is another post on the <input type=file> html
control you've posted in this group, yes? Are they focus on the same issue?
As the other members have mentioned, the "maxRequestLength" attribute will
limit the max length file that can be uploaded and the default is 4MB.
Also, I suggest that you have a look at the following tech article I've
mentioned in another thread:

#Uploading Files Using the File Field Control
http://msdn.microsoft.com/library/en-us/dnaspp/html/aspnet-fileupload.asp?fr
ame=true#aspnet-fileupload_topic2c

If you have anything unclear or any other findings, please feel free to
post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
B

Brian Henry

that fixed it thanks!


Steve C. Orr said:
You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Brian Henry said:
Hi, I am having a problem with an attachment system I made... it works with
files up to ~3MB in size then after that if you try to upload a file it just
goes to a "Page can not be displayed" page like it tried to do it but
errored... I thought changeing the max size for the file input box to about
100mb would fix it but nope

here is my page code and my code behind code...

==[html page]=============

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Attachments.aspx.vb" Inherits="SecureEmail.Attachments"%>
<%@ Register TagPrefix="cc1" Namespace="SecureEmail" Assembly="SecureEmail"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlTop" Src="../Themes/ctrlTop.ascx"
%>
<%@ Register TagPrefix="uc1" TagName="ctrlBottom"
Src="../Themes/ctrlBottom.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlLeftSide"
Src="../Themes/ctrlLeftSide.ascx" %>
<%@ Register TagPrefix="uc1" TagName="ctrlRightSide"
Src="../Themes/ctrlRightSide.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Reschini Secure E-Mail Network</title>
<meta content="SharePoint.WebPartPage.Document" name="ProgId">
<meta content="full" name="WebPartPageExpansion">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0"
MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table id="table1" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrltop id="CtrlTop1"
runat="server"></uc1:ctrltop></td>
</tr>
<tr>
<td vAlign="top" height="100%">
<table id="table2" height="100%" cellSpacing="0" cellPadding="0"
width="100%" border="0">
<tr>
<td vAlign="top"><uc1:ctrlleftside id="CtrlLeftSide1"
runat="server"></uc1:ctrlleftside></td>
<td vAlign="top" width="100%">
<TABLE id="table4" cellSpacing="0" cellPadding="0" width="100%"
bgColor="#a0c6e5" border="0"
class="toolbar">
<TR>
<TD>
<p align="left"><asp:button id="btnOK" runat="server" Text="OK"
Font-Size="8pt"></asp:button>&nbsp;<asp:button id="btnAddAttachment"
runat="server" Text="Add Attachment" Font-Size="8pt"></asp:button></p>
</TD>
<TD>&nbsp;</TD>
</TR>
</TABLE>
<table border="0" width="100%" id="table6" cellspacing="0"
cellpadding="0">
<tr>
<td>
<cc1:ctrlPageHeaderBox id="ctrlPageHeaderBox" runat="server"
Font-Size="8pt" AutoPostBack="True"
Text="Attachments"></cc1:ctrlPageHeaderBox></td>
</tr>
</table>
<table id="table3" cellPadding="0" width="100%" border="0">
<TBODY>
<tr>
<td><FONT face="Arial" size="1">Brows for an attachment using
the browse button, then
click add attachment to add it to the attachments
list.</FONT></td>
</tr>
<tr>
<td>&nbsp;<INPUT id="fileIn" type="file" name="fileIn"
runat="server">
<asp:Label id="lblErrorMsg" runat="server" Font-Size="8pt"
Font-Names="verdana" ForeColor="Red"></asp:Label>
<asp:customvalidator id="cvFile" runat="server" Font-Size="8pt"
ErrorMessage="Must specify a file"
Font-Names="Verdana"></asp:customvalidator></td>
</tr>
<tr>
<td>&nbsp;<FONT face="Arial" size="1">Current Attachments For
Message:</FONT></td>
</tr>
<tr>
<td><asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="0" width="350" id="table5" cellspacing="0"
cellpadding="5" style="border: 1px solid #A0C6E5">
<tr>
<td bgcolor="#A0C6E5" width="100%">
<font face="Arial" style="font-size:
8pt">Attachments</font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Size</span></font></td>
<td bgcolor="#A0C6E5" nowrap>
<font face="Arial"><span style="font-size:
8pt">Delete</span></font></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="100%" align="left">
<font size="2" face="Arial"><img border="0"
src="../images/attachfile.gif" width="17" height="13">
<%# DataBinder.Eval(Container.DataItem,"FileName")%>
</font>
</td>
<td nowrap align="right">
<font face="Arial" style="font-size: 8pt">
<%#
SecureEmail.Functions.FormatFileSize(DataBinder.Eval(Container.DataItem,"Fil
eSize"))%>
</font>
</td>
<td nowrap align="center">
<a href='attachments.aspx?action=remove&id=<%#
DataBinder.Eval(Container.dataitem,"ID")%>'>
<img border="0" src="../images/delete.gif" width="16"
height="16"></a></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td width="100%" align="left" style="border-top: 1px solid
#A0C6E5">
<p align="right">
<font face="Arial" style="font-size: 8pt">Total</font>
</td>
<td nowrap align="right" style="border-top: 1px solid
#A0C6E5">
<font face="Arial" style="font-size: 8pt">0.05
MB</font></td>
<td nowrap align="center" style="border-top: 1px solid
#A0C6E5">&nbsp;</td>
</tr>
</table>
</FooterTemplate> </asp:repeater></td>
</tr>
</table>
<p>&nbsp;</p>
</td>
<td vAlign="top"><uc1:ctrlrightside id="CtrlRightSide1"
runat="server"></uc1:ctrlrightside></td>
</tr>
</table>
</TD></TR>
<tr>
<td vAlign="top"><uc1:ctrlbottom id="CtrlBottom1"
runat="server"></uc1:ctrlbottom></td>
</tr>
</TBODY></TABLE></form>
</body>
</HTML>
============================================================================
=====
==== Code Behind ===========================================================


Public Class Attachments

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents btnOK As System.Web.UI.WebControls.Button

Protected WithEvents Repeater1 As System.Web.UI.WebControls.Repeater

Protected WithEvents fileIn As System.Web.UI.HtmlControls.HtmlInputFile

Protected WithEvents btnAddAttachment As System.Web.UI.WebControls.Button

Protected WithEvents cvFile As System.Web.UI.WebControls.CustomValidator

Protected WithEvents ctrlPageHeaderBox As SecureEmail.ctrlPageHeaderBox

Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

' if there isn't an attachments table already...

If Session("AttachmentsTable") Is Nothing Then

' get schema from db and create a table from it...

Dim dt_attachments As New DataTable

dt_attachments.Columns.Add(New DataColumn("FileName", GetType(String)))

dt_attachments.Columns.Add(New DataColumn("FileSize", GetType(Int32)))

Dim dc_ID As DataColumn = dt_attachments.Columns.Add("ID", GetType(Integer))

dc_ID.AutoIncrement = True

dc_ID.AutoIncrementSeed = 1

dc_ID.AutoIncrementStep = 2

dc_ID.ReadOnly = True

dt_attachments.PrimaryKey = New DataColumn() {dt_attachments.Columns("ID")}

dt_attachments.Columns.Add(New DataColumn("AttachmentData",
GetType(Byte())))

Session("AttachmentsTable") = dt_attachments

End If

If Not Request.QueryString("action") Is Nothing Then

Select Case Request.QueryString("action").ToLower

Case "remove"

Dim DR_ROW As DataRow

DR_ROW = DirectCast(Session("AttachmentsTable"),
DataTable).Rows.Find(Convert.ToInt32(Request.QueryString("ID")))

DR_ROW.Delete()



End Select

End If

End If

Me.Repeater1.DataSource = Session("AttachmentsTable")

Me.Repeater1.DataBind()

End Sub





Private Sub AddAttachment()

If Me.fileIn.Value.Trim.Length = 0 Then

Me.cvFile.IsValid = False

Else

Try

Me.lblErrorMsg.Visible = False

Dim AttachedFileCollection As HttpFileCollection

Dim a As HtmlInputFile

Me.fileIn.MaxLength = (100 * 1024) ' 100 MB upload max

Dim MyFile As HttpPostedFile

Dim FileLength As Integer

Dim FileName As String

Dim FileStream As System.IO.Stream

AttachedFileCollection = Request.Files

MyFile = AttachedFileCollection(0)

FileLength = MyFile.ContentLength

Dim FileData(FileLength) As Byte





FileStream = MyFile.InputStream

FileStream.Read(FileData, 0, FileLength)





Me.cvFile.IsValid = True

Dim dr_row As DataRow = DirectCast(Session("AttachmentsTable"),
DataTable).NewRow

dr_row("FileName") = IO.Path.GetFileName(MyFile.FileName).ToUpper

dr_row("FileSize") = MyFile.ContentLength

dr_row("AttachmentData") = FileData

DirectCast(Session("AttachmentsTable"), DataTable).Rows.Add(dr_row)

Catch ex As Exception

Me.lblErrorMsg.Visible = True

Me.lblErrorMsg.Text = "Error uploading file: " & ex.Message

End Try

Me.Repeater1.DataBind()

End If

End Sub

Private Sub btnAddAttachment_Click(ByVal sender As System.Object, ByVal
e
As
System.EventArgs) Handles btnAddAttachment.Click

AddAttachment()

End Sub

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOK.Click

Response.Redirect("Compose.aspx")

End Sub

End Class
 
B

Brian Henry

say if i wanted a 25600KB max upload (25mb) how would i instead of going to
a page not found page, instead give them a vaildation message that it cant
be this big? thanks
 
L

Lau Lei Cheong

Seems you'll want to check Request.ContentLength at Application_BeginRequest
event
of Global.asax.
 
S

Steven Cheng[MSFT]

Hi Brian,

As for the error handling of the exceeding MaxFile upload limiation in
asp.net. Currently there seems haven't any graceful way. This is because
the asp.net reject the too large request and close the connection between
those events such as BeginRequest or Application_Error which we can handle
via code. So there hasn't any better means to handle it except set the
maxRequestLength to a large size and let the file be uploaded and then
discard it. In fact, you can use the <location> element in asp.net
web.config file to set the
"maxRequestLenght" attribute to a large value only for the fileuploading
page, just like below:

<configuration>
<location path="UploadPage.aspx">
<httpRuntime maxRequestLength="128"/>
</location>
</configuration>

#<location> Element
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/ht
ml/gngrflocationelement.asp

In addition, here are some former threads in the newsgroup discussing on
the same problem:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=#Pk3wxMHEHA.119
2%40TK2MSFTNGP11.phx.gbl&rnum=5&prev=/groups%3Fq%3Dasp.net%2Bhandle%2Bupload
%2Bfile%2Berror%26hl%3Den%26lr%3D%26ie%3DUTF-8%26start%3D0%26sa%3DN

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=OnZOezyuCHA.2380%
40TK2MSFTNGP11&rnum=3&prev=/groups%3Fq%3Dasp.net%2Bupload%2Bmax%2Bsize%2Bche
ck%26ie%3DUTF-8%26hl%3Den

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top