User-627724879 posted
This is what I put to gether a few years ago and still use,
http://www.codeplex.com/ExImageResizer.
You can also set a filter to limit the file types on the client, but you should always check on the server:
<tr>
<td align="left">
Picture
</td>
<td align="left">
<asp:FileUpload ID="fPicture" runat="server" CssClass="formField" />
<asp:RegularExpressionValidator runat="server" ID="rvfPicture" ControlToValidate="fPicture"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpg|.JPG|.png|.PNG|.gif|.GIF)$"
ErrorMessage="You can only upload .jpg, .gif or
.png image types." />
</td>
</tr>
Private _UploadedFileName As String = String.Empty
Private ReadOnly Property UploadedFileName() As String
Get
If String.IsNullOrEmpty(_UploadedFileName) Then
If fPicture.HasFile Then
_UploadedFileName = HttpUtility.UrlDecode(Path.GetFileName(fPicture.FileName)).Replace(" ", "-")
ElseIf IsNothing(ViewState("PictureFileName")) = False Then
_UploadedFileName = ViewState("PictureFileName").ToString
End If
End If
Return _UploadedFileName
End Get
End Property
Private _PhotoExtension As String = String.Empty
Private ReadOnly Property PhotoExtension() As String
Get
If String.IsNullOrEmpty(_PhotoExtension) Then
_PhotoExtension = Path.GetExtension(fPicture.FileName)
End If
Return _PhotoExtension
End Get
End Property
If fPicture.HasFile Then
If PhotoExtension.ToLower.Contains("jpg") = False And _
PhotoExtension.ToLower.Contains("gif") = False Then
Response.Write("<B>You can Only Upload JPGs or GIFs</B>")
Exit Sub
End If
........
lgi.StoreImage(GalleryHelper.GetAlbumThumbNailsDirectory( _
ddlAlbums.SelectedItem.Text), _
Path.GetFileName(lThumbnailFileName), _
lOriginalFileName, _
Convert.ToInt32(txtWidth.Text), _
Convert.ToInt32(txtHeight.Text))
.......