Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Loading AxSpreadsheet from a .NET resource

Hi,

I'd like to be able to include my Excel templates (XML files) as resources
in the assembly rather than separate files only I can't find a method of
loading these into the AxSpreadsheet. The XMLUrl property on accepts URL's
not strings so the only way I can think of is to extract the resource, save
to a temprary file, load and then delete the temporary file. I'd like to find
a more elegant solution if I can. Any ideas anyine?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Loading AxSpreadsheet from a .NET resource

Hi

We can add the excel file(e.g. xls) into the project, and in the properties
to change the build action into embedded resources, so that the xls file
will be compiled into the assebmly.

And then we can use he code below to retrieve the xls file and write to
disk for use.

string[] names=Assembly.GetExecutingAssembly().GetManifestR esourceNames();
System.IO.Stream sm =
Assembly.GetExecutingAssembly().GetManifestResourc eStream(names[0]);
byte[] bts = new byte[sm.Length];
FileStream fs =new );
sm.Position = 0;
int i = (int)sm.Read(bts,0,(int)sm.Length);
fs.Write(bts,0,i);
fs.Close();
sm.Close();

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Loading AxSpreadsheet from a .NET resource

Peter,

Thanks, I had hoped I might be able to load the resource directly into the
AxSpreadsheet but this is a useable solution.

""Peter Huang" [MSFT]" wrote:

Hi

We can add the excel file(e.g. xls) into the project, and in the properties
to change the build action into embedded resources, so that the xls file
will be compiled into the assebmly.

And then we can use he code below to retrieve the xls file and write to
disk for use.

string[] names=Assembly.GetExecutingAssembly().GetManifestR esourceNames();
System.IO.Stream sm =
Assembly.GetExecutingAssembly().GetManifestResourc eStream(names[0]);
byte[] bts = new byte[sm.Length];
FileStream fs =new );
sm.Position = 0;
int i = (int)sm.Read(bts,0,(int)sm.Length);
fs.Write(bts,0,i);
fs.Close();
sm.Close();

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Loading AxSpreadsheet from a .NET resource

Peter,

Rather than use the root of C: (which is locked down under group policy) I'm
trying to use the Isolated Storage directory hive. However, although I can
create the file I can't get a fully resolved path to it!! Any ideas?

""Peter Huang" [MSFT]" wrote:

Hi

We can add the excel file(e.g. xls) into the project, and in the properties
to change the build action into embedded resources, so that the xls file
will be compiled into the assebmly.

And then we can use he code below to retrieve the xls file and write to
disk for use.

string[] names=Assembly.GetExecutingAssembly().GetManifestR esourceNames();
System.IO.Stream sm =
Assembly.GetExecutingAssembly().GetManifestResourc eStream(names[0]);
byte[] bts = new byte[sm.Length];
FileStream fs =new );
sm.Position = 0;
int i = (int)sm.Read(bts,0,(int)sm.Length);
fs.Write(bts,0,i);
fs.Close();
sm.Close();

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Loading AxSpreadsheet from a .NET resource

Hi

IsolatedStorage's concrete file path is controled by .NET framework, we
should always use IsolatedStorage's method to write/read the data.
Usually it is in the directory below.
C:\Documents and Settings\v-phuang\Local Settings\Application
Data\IsolatedStorage
e.g. You will find it is not predictable.
C:\Documents and Settings\v-phuang\Local Settings\Application
Data\IsolatedStorage\3tc5ggky.5gr\dmwbcbtm.f2w\Url .kddvnk2rsg3bfnvnoazlcymom
ubiim5q

You can use the Isolated Storage Tool (Storeadm.exe) utility to list and
remove the Isolated Storage files that are created with this console
application.

IsolatedStorageFile Class
Represents an isolated storage area containing files and directories.

Here is some code about how to read and write to files with
IsolatedStorageFileStream
Reading and Writing to Files
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconreadingwritingtofiles.asp

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resource Scheduling/loading Imti Excel Worksheet Functions 1 June 22nd 08 06:37 PM
Resource loading (difficulty with date functions) Russ Excel Worksheet Functions 0 June 6th 08 03:54 AM
Using axSpreadsheet Kaustav Excel Worksheet Functions 0 October 10th 06 05:44 PM
Available Resource Error ken8795 Excel Discussion (Misc queries) 4 July 17th 06 03:30 AM
Opening an Excel file in OWC10.AxSpreadSheet santhosh.b Excel Programming 1 September 16th 05 11:07 AM


All times are GMT +1. The time now is 01:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"