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> <asp:button id="btnAddAttachment"
runat="server" Text="Add Attachment" Font-Size="8pt"></asp:button></p>
</TD>
<TD> </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> <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> <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"> </td>
</tr>
</table>
</FooterTemplate> </asp:repeater></td>
</tr>
</table>
<p> </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
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> <asp:button id="btnAddAttachment"
runat="server" Text="Add Attachment" Font-Size="8pt"></asp:button></p>
</TD>
<TD> </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> <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> <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"> </td>
</tr>
</table>
</FooterTemplate> </asp:repeater></td>
</tr>
</table>
<p> </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