c# - [Content_Types].xml <Override> element missing -


i'm trying create 2007+ excel document (.xlsx), using nothing .net 4.0 built-in classes. can't use third party libraries.

actually it's done part, problem i'm facing that, package i'm creating seems fail on creation of [content_types].xml file, mean lacks <override> elements, , <default> elements created.

i'm pretty sure problem @ point create relationships between packages, don't know how make work, , documentation , examples on package , zippackage classes surprisingly scarce.

maybe i'm missing step...does 1 has clue? please

this similar code produces excactly same problem

public void createpackage()         {             string dir = @"f:\proyectos\excel_stackoverflow\windowsformsapplication1\windowsformsapplication1\resources";          uri file1_abs = new uri(string.format(@"{0}\1.xml", dir), urikind.absolute);                 uri file1_rel = new uri(@"/oddcontent/file1.xml", urikind.relative);                  using (zippackage expkg = (zippackage)package.open(string.format(@"{0}\temp.zip", dir), filemode.create))                 {                     zippackagepart file1part = (zippackagepart)expkg.createpart(file1_rel, system.net.mime.mediatypenames.text.xml);                     using (filestream fs1 = new filestream(file1_abs.localpath, filemode.open, fileaccess.read))                     {                         form1.copystream(fs1, file1part.getstream());                     }                     expkg.createrelationship(file1_rel, targetmode.internal, "sometype");                     expkg.flush();                     expkg.close();                     }             }          private static void copystream(stream source, stream target)         {             const int bufsize = 0x1000;             byte[] buf = new byte[bufsize];             int bytesread = 0;             while ((bytesread = source.read(buf, 0, bufsize)) > 0)                 target.write(buf, 0, bytesread);         } 

and [content_types].xml file generates given code is:

<?xml version="1.0" encoding="utf-8"?> <types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"> <default contenttype="text/xml" extension="xml"/> </types> 

but i'm expecting [content_types].xml file content:

<?xml version="1.0" encoding="utf-8"?> <types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"> <default contenttype="text/xml" extension="xml"/> <override partname="...................."/> </types> 

the "override" element put types list, once there part stored default extension different content type.

here's updated version create "override" element file1part:

        uri file1_rel = new uri(@"/oddcontent/file1.xml", urikind.relative);         uri file2_rel = new uri(@"/oddcontent/file2.xml", urikind.relative);          using (zippackage expkg = (zippackage)package.open(string.format(@"{0}\temp.zip", dir), filemode.create))         {             zippackagepart p2 = (zippackagepart)expkg.createpart(file2_rel, system.net.mime.mediatypenames.text.xml);             zippackagepart file1part = (zippackagepart)expkg.createpart(file1_rel, "application/vnd.openxmlformats-officedocument.wordprocessingml.documents.main+xml"); 

note: type-copied mime type vnd... image, might have typos, feel free fix.

the created [content_types].xml looks this:

<?xml version="1.0" encoding="utf-8"?> <types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"> <default extension="xml" contenttype="text/xml" /> <default extension="rels" contenttype="application/vnd.openxmlformats-package.relationships+xml" /> <override partname="/oddcontent/file1.xml" contenttype="application/vnd.openxmlformats-officedocument.wordprocessingml.documents.main+xml" /> </types> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -