cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Regular Visitor

Modifying the Layout file that is embedded in a pbix file

I know how to disassemble a pbix file by changing the extension to .zip and then oening it.  If I then change the extension back to .pbix I can then open it in Power BI.  However, I would like to modify the Layout file that is exposed when you disassemble the pbix.  But when I do that and change the extension of the .zip to .pbix, I get a corrupted file message when I try to open in Power BI.  This happens no matter how small and inocuous the change is.  

 

Is there any way to do this without getting the corrupted file message?

23 REPLIES 23
New Member

I found that when I was saving, the WriteAllTextAsync was prepending 2 extra bytes.. using FlexHex I could see that the original did not have that.

 

2cdba354-cdd6-438c-8daf-e0aa18da5772.jpg

 

To fix this I just saved with WriteAllTextAsync with Encoding.Unicode. Re-opened as bytes and saved skipping the first 2 bytes in question.

 

var serializedFile = JsonConvert.SerializeObject(_layoutModel);
await System.IO.File.WriteAllTextAsync(Filepath, serializedFile, Encoding.Unicode);

var asBytes = await System.IO.File.ReadAllBytesAsync(Filepath);
await System.IO.File.WriteAllBytesAsync(Filepath, asBytes.Skip(2).ToArray());

 

Just as an FYI, as others have mentioned I also needed to edit [Content_Type].xml and remove the Override tag with the PartName == "/SecurityBindings". After that powerbi loaded it fine (ignoring the validation checks it did).

 

After a little research I found that it's a marker for byte order of unicode (I'd gussed it was this, but didn't know for sure until now). Anyway, I've update the code pushed here yesterday. (Couldn't find an edit link for my previous post)

 

 

public async Task Save()
{
    var layoutFile = JsonConvert.SerializeObject(_layoutModel);
    await System.IO.File.WriteAllTextAsync(Filepath, layoutFile, Encoding.Unicode);

    IEnumerable<byte> layoutAsBytes = await System.IO.File.ReadAllBytesAsync(Filepath);
    layoutAsBytes = StripUnicodeByteOrder(layoutAsBytes);
    await System.IO.File.WriteAllBytesAsync(Filepath, layoutAsBytes.ToArray());
}

public static IEnumerable<Byte> StripUnicodeByteOrder(IEnumerable<byte> bytes)
{
    if (bytes.ElementAt(0) == 0xFF && bytes.ElementAt(1) == 0xFE)
        bytes = bytes.Skip(2);

    return bytes;
}

 

 

Hi @instinct46 , 

 

Could you explain where and how one should exactly run this code? In my case, I don't want to change the lay-out file but I want to change the datamodelschema to programmatically add measures. 

 

Thanks in advance.

Regular Visitor

When I remove "<Override PartName="/SecurityBindings" ContentType="" />" in the [Content_Types].xml root file, I can edit the PBIX file and open it without problem.

Hey,
I tried your solution, it's working great !
many thanks !

Hi 

 

When I try to just remove the "<Override PartName="/SecurityBindings" ContentType="" />" in the [Content_Types].xml root file and try to re construct the pbix by zipping the file, still I am unable to open the file. Please advise.

Try deleting the Security Bindings file rather than removing this code.

 

Also, when you say zipping the file... See my comment above. The extracted file should not be re-zipped. Instead, the extracted Layout file should be updated and then copied into the original .zip folder (Delete Security Bindings file from here). This should then be renamed back to .pbix

Frequent Visitor

Its doen´t works for me

 

Frequent Visitor

Sorry, it´s doesn´t work for me

Frequent Visitor

Hey,

 

Its working!! thank you.

Frequent Visitor

Same issue here, but even without rezipping the file, it causes corruption :(,
hope it will be possible to deal with the Layout directly one day.

Regular Visitor

I can change the Layout file by doing the following:

 

Change .pbix to .zip

Extract file

Amend and save extracted Layout file

Copy amended Layout file into original zipped folder *

Rename .zip to .pbix

 

*This is required. Re-zipping the extracted file will cause corruption

Anonymous
Not applicable

I second this issue. Has anybody already opened an "idea" for this topic. Changing these parameters programmatically would be a huge enterprise BI update! Or it is quite a bummer that we can see all these parameters but not able to change it.

 

@v-yuezhe-msft in this case opening Power BI Desktop is definitely not a satisfying answer.

But which changes can we do so far, and everyone else which changes have you done in the zip? 

E.g. changing the registeredresources is possible.

New Member

Did you find solution for this issue? I too am facing the same issue while making changes to a visual through layout file.

Frequent Visitor

I have the same issue. I can open and modify the Layout file, but this corrupts the pbix file. My issue is that I used to use an arcgis esri map, but am not able to delete this custom visual via PBI Desktop (it doesn't show up in the delete visuals list). I was trying to change 

\"singleVisual\":{\"visualType\":\"esriVisual\",\"objects\":{}

to

\"singleVisual\":{\"visualType\":\"map\",\"objects\":{}

If anybody has any idea how to delete the esri visual/component, I would be grateful.

EDIT:  I have also disabled the "use esri maps" from the options, but still the esri map icon is visible in the visuals list. Is this normal? I don't want app viewers to get the  esri map notification when they open the app for the first time. 

Regular Visitor

Hi, have you found a solution for this yet?

No.

Microsoft
Microsoft

@maceyak,

I would recommend you follow the instructions in the blog below to change layout.

https://powerbi.tips/2018/01/introducing-layouts/

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks, Lydia.  But I am not asking about changing the visual layout of a page.  I am asking about changing a particular file named "Layout" that is exposed when you deconsturuct a PBIX file.  This file contains the formatting information for the page and the text that the designer has entered into it.  To get to this file, you do the following to a PBIX file:

 

1. Changed the extension from ".pbix' to ".zip".

2.  Open the zip file.  You will see several folders.  Go into the Report folder, and you will see the Layout file.

 

--Joey

@maceyak,

What property do you change in the Layout file? There is no official articles stating that what we can do or can't do in the Layout file.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors