473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to upload text and excel files in dot net

How do i specify the file type as text and excel when i want to upload a file using dotnet

My code is as follows:

<script language="C#" runat="Server">
//Event Handler for the upload button
void UploadFile(object Sender,EventArgs E)
{
if (File1.PostedFile !=null) //Checking for valid file
{
// Since the PostedFile.FileNameFileName gives the entire path we use Substring function to rip of the filename alone.
string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFi le.FileName.LastIndexOf("\\") + 1) ;
string StrFileType = File1.PostedFile.ContentType;

// string StrFileType = File1.PostedFile.ContentType("video/mpeg") ;

int IntFileSize =File1.PostedFile.ContentLength;
//Checking for the length of the file. If length is 0 then file is not uploaded.
if (IntFileSize <=0)
Response.Write(" <font color='Red' size='4'>Uploading of file " + StrFileName + " failed </font>");
else
{
if (File1.PostedFile.ContentType == "text/txt")
{
File1.PostedFile.SaveAs(Server.MapPath(".\\" + StrFileName));
}
Response.Write( "<font color='blue' size='4'>Your file " + StrFileName + " of type " + StrFileType + " and size " + IntFileSize.ToString() + " bytes was uploaded successfully</font>");
}
}
}
</script>
Jun 8 '07 #1
0 1015

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John | last post by:
I am using Excel to save a spreadsheet in .csv format. This creates a text file with extension .csv But when I try to upload the file to the server by checking for its MIME type using $_FILE I get...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
3
by: Prakash | last post by:
Hi, We face problems uploading excel (with macros) documents using HTML File Upload. The file contents are corrupted while viewing the same. However, we are able to upload excel (w/o. macros)...
3
by: jhanzl | last post by:
All - I am looking into a way of uploading just the first portion of a large (> 100M) .csv (text) file to the server. Ultimately what I want to do is read the first line of the .csv file, which...
5
by: Seok Bee | last post by:
Dear Experts, I currently trying to use the FileUpload control from asp.net 2.0 to upload files. The uploading of the file I would like to store it in the Access Database. Unfortunately, I've no...
3
by: c676228 | last post by:
Hi everyone, I will develop a program to enroll a group of people on-line. Since we don't have number limitation for the people in the group. I am wondering if there is any company allow people...
6
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
I have a strange problem when uploading a PDF document to a web-server. When I try this to a web-server running Apache 2 on a FC 4, it fails. Firefox says that the document contain no data. If I...
5
by: shantanu | last post by:
Hi i am trying to upload a txt file thru this code, but its not updating the data. is this code fine. Or can anybody please suggest me some other meathod to do the same. its urgent please help ...
1
by: =?Utf-8?B?TGFtaXM=?= | last post by:
HI, I am doing an aspx application and need to let my users be able to edit the information in my database by the page. My first Idea was to let them export the information to an excel file at...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.