C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Its Urgent... File Upload


Posted Date: 27 Sep 2008      Posted By: Pradeep Kumar      Member Level: Gold     Points: 1   Responses: 4



How to get the size of a file or image while uploading???




Responses

Author: muralidhar    27 Sep 2008Member Level: GoldRating: 3 out of 53 out of 53 out of 5     Points: 3

hai,

you can get the file size of the uploading file by using

FileUpload1.PostedFile.ContentLength;

the above statement will give you the file size.

file can be of any type(doc, rtf, jpg,gif etc).

regards,
Muralidhar.

Regards,
Muralidhar.



Author: puneet    27 Sep 2008Member Level: BronzeRating: 1 out of 5     Points: 1

FileUpload1.PostedFile.ContentLength




it will

give the
size of
file



Author: Ravi Kiran Nedunuri    27 Sep 2008Member Level: GoldRating: 5 out of 55 out of 55 out of 55 out of 55 out of 5     Points: 15

hi please check all the details regarding file upload conrol

declare a file upload and span in .aspx page

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
please upload a image:</td>
<td>
<asp:FileUpload ID="fileup" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="btnFileup" runat="server" Text="save" OnClick="btnFileup_Click" /></td>
</tr>
</table>
</div>
<span id="sp" runat="server">
FileName: <asp:Label ID="lblFileName" runat="server"></asp:Label>
<br />
ImageType: <asp:Label ID="lblImgType" runat="server">
</asp:Label>
<br />
Image Saved At: <asp:Label ID="lblPath" runat="server"></asp:Label>
<br />
<asp:Label ID="lblMessage" runat="server"></asp:Label>
<br />
</span>
</form>
</body>
</html>
in code behind write the following code


using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
sp.Visible = false;
}
protected void btnFileup_Click(object sender, EventArgs e)
{
if (fileup.PostedFile.ContentLength > 0)
{
if (fileup.PostedFile.FileName.EndsWith(".bmp") || fileup.PostedFile.FileName.EndsWith(".gif") || fileup.PostedFile.FileName.EndsWith(".png") || fileup.PostedFile.FileName.EndsWith(".jpeg") || fileup.PostedFile.FileName.EndsWith(".jpg"))
{


string s = Server.MapPath("images\\");//this saves the image in our application where our project is located.(saves in images folder)

fileup.PostedFile.SaveAs(s );
lblFileName.Text = fileup.FileName.ToString();//Water lilies.jpg
//lblFileName.Text = fileup.PostedFile.FileName.ToString(); C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water lilies.jpg
lblImgType.Text = fileup.PostedFile.ContentType.ToString();
lblPath.Text = s;
lblMessage.Text = "upload suceess";
sp.Visible = true;
}

else
{
sp.Visible = false;
Response.Write("invalid image format");
//ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('Invalid Image Format');</script>'");
}
}
}
} Regards
N.RaviKiran



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Without fileupload control
Previous : PDF Maker By C# Code
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use