Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
maceyak
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?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I was struggling with this issue recently, and my solution is the following:

 

- Change the extension from ".pbix" to ".zip"

- Do not unzip the ".zip" file during this process

- Extract the "Layout" file from the "Report" folder in the ".zip" file

- Open the "Layout" file with Notepad++. (VERY IMPORTANT)

- Make your modifications in the Layout file

- Substitute the old "Layout" file with the new one

- Delete "SecurityBindings" file in the ".zip" file

- In the [Contents_type].xml delete the following text: 

"<Override PartName="/SecurityBindings" ContentType="" />"

- Change the extension from ".zip to ".pbix"

- The file will open without breaks

 

Hope it helps!

View solution in original post

33 REPLIES 33
anujagupta
New Member

hello all,

 

i am trying to modify the layout file content using powershell script . When i m trying to user Set content with -Encoding "unicode" . After that pbix not able to open and display error corrpupted. Also in notpad ++ is shows "UTF-16 LE BOM encoding. But origial Layout ending was "utf-16 Little Endian. 

 


Set-Content -Path "C:\PowerShell\newre\newRe\Report\Test" -Value $final -Encoding unicode

 

can somebody help me out to solve it.

Anonymous
Not applicable

I created an Idea to address this question, please vote:

Renaming dataset measures can't break client reports (change reference from name to ID)

https://ideas.powerbi.com/ideas/idea/?ideaid=649ec802-682b-ec11-b76a-281878e608e9

Anonymous
Not applicable

I was struggling with this issue recently, and my solution is the following:

 

- Change the extension from ".pbix" to ".zip"

- Do not unzip the ".zip" file during this process

- Extract the "Layout" file from the "Report" folder in the ".zip" file

- Open the "Layout" file with Notepad++. (VERY IMPORTANT)

- Make your modifications in the Layout file

- Substitute the old "Layout" file with the new one

- Delete "SecurityBindings" file in the ".zip" file

- In the [Contents_type].xml delete the following text: 

"<Override PartName="/SecurityBindings" ContentType="" />"

- Change the extension from ".zip to ".pbix"

- The file will open without breaks

 

Hope it helps!

If it works

Anonymous
Not applicable

GREAT! Saved my week   \o/

Thanks @Anonymous 

Anonymous
Not applicable

Yes, This worked. Because of this so much time is saved. Don't know how to thank you.

Anonymous
Not applicable

This worked!  Thanks so much!  It saved me hours of having to rebuild the file

instinct46
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).

 

This is what worked for me.

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.

I don't believe that code is needed if you make edits with Notepad ++ and not Notepad. I kept getting a corrupt file despite thinking I'd followed the instructions exactly, then I came across this and realized Notepad was the culprit (and I later noted that the instructions above explicity say in all caps that it's VERY IMPORTANT to use Notepad ++ to make edits, yet I had somehow overlooked them 😀).

elimcd79_0-1665524901501.png

 

I hope this is what is causing your issue as well!

Anonymous
Not applicable

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 !

Anonymous
Not applicable

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

Anonymous
Not applicable

Its doen´t works for me

 

Anonymous
Not applicable

Sorry, it´s doesn´t work for me

Anonymous
Not applicable

Hey,

 

Its working!! thank you.

CBourlet
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.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.