473,795 Members | 2,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.Net C# Excel Upload Question

Good Day All,

Sorry if I am posting in the wrong forum, hopefully someone will be able to
push me in the right direction. What I am trying to accomplish is allowing a
client to upload an Excel file and then I need to access the Excel file
without saving the file directly to the server. What I am eventually going to
do is save the Excel data into a database. Here is a sample of what I am
trying to do, and I may be way off track here.

if ( filMetricFile.P ostedFile != null )
{
// Get a reference to PostedFile object
HttpPostedFile _metricFile = filMetricFile.P ostedFile;

// Get size of uploaded file
int nFileLen = _metricFile.Con tentLength;

// make sure the size of the file is > 0
if( nFileLen > 0 )
{
// Allocate a buffer for reading of the file
byte[] _metricData = new byte[nFileLen];
// Read uploaded file from the Stream
_metricFile.Inp utStream.Read(_ metricData, 0, nFileLen);

OleDbConnection ExcelConnection = new OleDbConnection (
@"Provider=Micr osoft.Jet.OLEDB .4.0;Data Source="
+ _metricFile + ";Extended Properties=Exce l 8.0;");

ExcelConnection .Open();

//Do something with the ExcelConnection
}
}

And of course I am sure you can see I am missing something. When I try the
ExcelConnection .Open() I will get a an error stating that the object is read
only.

So I’m not sure if what I am doing is even possible, but any help would be
greatly appreciated. I just want to process the Excel file while in memory
and not have to save the file directly to the server first.

Thanks,
Jake

Nov 16 '05 #1
1 2825
Jake:

I don't believe there is going to be an easy way to do this. Excel
runs as a separate process, and you can't just pass it a pointer or a
reference to a block of memory sitting in the web application.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 19 Nov 2004 11:35:20 -0800, "Jake"
<Ja**@discussio ns.microsoft.co m> wrote:
Good Day All,

Sorry if I am posting in the wrong forum, hopefully someone will be able to
push me in the right direction. What I am trying to accomplish is allowing a
client to upload an Excel file and then I need to access the Excel file
without saving the file directly to the server. What I am eventually going to
do is save the Excel data into a database. Here is a sample of what I am
trying to do, and I may be way off track here.

if ( filMetricFile.P ostedFile != null )
{
// Get a reference to PostedFile object
HttpPostedFi le _metricFile = filMetricFile.P ostedFile;

// Get size of uploaded file
int nFileLen = _metricFile.Con tentLength;

// make sure the size of the file is > 0
if( nFileLen > 0 )
{
// Allocate a buffer for reading of the file
byte[] _metricData = new byte[nFileLen];
// Read uploaded file from the Stream
_metricFile.In putStream.Read( _metricData, 0, nFileLen);

OleDbConnectio n ExcelConnection = new OleDbConnection (
@"Provider=Mic rosoft.Jet.OLED B.4.0;Data Source="
+ _metricFile + ";Extended Properties=Exce l 8.0;");

ExcelConnectio n.Open();

//Do something with the ExcelConnection
}
}

And of course I am sure you can see I am missing something. When I try the
ExcelConnectio n.Open() I will get a an error stating that the object is read
only.

So I’m not sure if what I am doing is even possible, but any help would be
greatly appreciated. I just want to process the Excel file while in memory
and not have to save the file directly to the server first.

Thanks,
Jake


Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
12377
by: Vikram | last post by:
Hi, Given below is my task. An user can open the xls file from my website (loaded on the top frame). After filling the Excel, he can click a send button at the bottom frame. By clicking the button i have to save the file in a shared directory on the web server by a unique name. Is it possible ?
3
5829
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) documents successfully. Is there anything we have to take care of, while handling uploads of excel documents with macros? Thanks in advance,
3
4134
by: Rik Moed | last post by:
Hi, I am having a problem with Excel 2003 worksheets when I upload them using the HtmlIputFile. After the upload, I start to download the worksheet and it appears to be currupt. I recieve the error: <FileName> cannot be accessed. The file may be read-only, or you may be trying to access a read-only location. Or, the server the document is stored on may not be responding.
1
2227
by: Daniel | last post by:
Hi, can u explain to me what is the path need to use in order to upload and download the file based on below solution: 1.Set up a folder that both the web app and SQL server can get to. 2.Do a simple file upload from the web app what is DTS package and how to apply it? 3.Set up a DTS package to periodically check the folder to do an import. Your help will be appreciated.
6
6769
by: Daniel | last post by:
Hi all, Can i open and edit the excel sheet on web page after downloading? After editing, i close the web page and the excel file auto upload to the server. Is it possible? I really struggling about the ability. If not, what advice can u provide? thank you in advance. ur help will be appreaciated.
1
4822
by: vic pahilan | last post by:
hi, pls need help. I need to upload excel field to sql server field. the user will choose excel file then i will show the fields inside that excel file then copy it into sql server field. I already done the rest but I dont know how to start coding with the command to upload. i use the listview control for excel same with for sql server to display their fields. hope u can help. tnx n advance
3
8012
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 to upload an excel sheet which contains data about the people in the group and the asp program can import the data into the program direclty, so the customer don't have to type each person's info individual sin it's error prone and time consuming...
1
2853
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 local machine where they can edit it och then upload the file by the page again to save down their changes down to the database. Now, this is the code I am using to Upload from sql to excel : HttpResponse response = HttpContext.Current.Response;
5
4621
by: priyammaheshwari | last post by:
Hi all, I have a MS Access database in which requests made by people is stored,but a coulmn for cost is left empty which is suppose to be populated by the administrator.Now the administrator wants that there should be some functionality by which he would just have to upload an excel file containing the name and cost per person and the cost should be populated in access database against the respective name of people. I am not able to figure...
0
10439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.