ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loading AxSpreadsheet from a .NET resource (https://www.excelbanter.com/excel-programming/340264-loading-axspreadsheet-net-resource.html)

Paul Hasell

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?

Peter Huang [MSFT]

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.


Paul Hasell

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.



Paul Hasell

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.



Peter Huang [MSFT]

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.



All times are GMT +1. The time now is 06:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com