How to manually fix content error in Microsoft Word


Word2013_error1

Today while I was editing a document suddenly Word crashed and the document became unable to be opened. Every time I wanted to open it the same error was:

We’re sorry. We can’t open DocumentName.docx because we found a problem with its contents.
When I want to see Details the following message shows:
Unspecified error
Location: Part: /word/document.xml, Line 2, Column: 0.

Then I wanted to open auto-saved version of the document, the same error appeared. So I changed the DocumentName.docx  file in to DocumentName.zip, and extract the content, found document.xml file and opened it in Notepad++.

The picture below shows the content of the DocumentName.docx file, renamed in to zip and extracted:

Word2013_error2

If you didn’t know the word document with doc or docx extension is actually zip file, which you can extract.

I have opened the docuemnt.xml and try to find error in second line. This was mission impossible because all xml content is placed in this line. As you can see on the picture below:

Word2013_error3

To find which element cause the content problem we have to format XML content. I prefer using Notepad++ and XML Tool PlugIn. It can be installed through Plungins menu of Notepad++.

Word2013_error4

To format xml content choose option Pretty print (XML only – with line breaks) . After the content is formatted, back the Document.xml to zip, change the extension from zip to docx, and open the word document.

The same error appear, but when you choose for details you can read in which line is the error. Find the line in Notepad++ and delete whole tag element:

Word2013_error7

Copy document.xml back in to zip file, rename the extension and try to open. If you have another error, repeat the process again, otherwise your document is opened.

Word2013_error8

Advertisements

WinDays13 – kratki utisci, pptx datoteka i demo primjeri


Još uvijek traje jedna od najvecih Microsoft konferencija u regionu, i nakon dva dana konferencije mogu reći da su ovi WinDaysi do sada najbolje organizirana konferencija. Preko 1000 registrovanih polaznika i stotinjak predavača samo su neke od statističkih brojki ove konferencije.

Da je ovo prava developerska konferencija između ostalog možemo se uvjeriti na dobroj posjećenosti dev predavanja. Prvog dana konferencije najzanimljiviji dijelovi možemo kazati da su bili ITPro i Dev keynote , a posebno je interesantnan bio keynote od Damir Dobrića koji je zbog štrajka radnika avio-kompanije, javljanje održao preko Skypea sa ljubljnskog aerodroma. Drugog dana nastavilo se u dobrom raspoloženju, a sada već tradicionalna večera predavača desila se u restoranu nedalok od konferencije u pravom istarskom stilu.

Drugog dana konferencije održao sam predavanje na temu MVVM u razvoju WP8 i Windos store aplikacija, i sa zadovoljstvo mogu reći da je proteklo u dobroj atmosferi sa prepunom salom. Kao što sam najavio prethodno moje predavanje oko MVVM tehnike na WP8 i WinRT bilo je drugog dana konferencije. Ovim pute se zahvaljujem svim posjetiocima predavanja i kao što sa obećao demo primjere i prezentacijku datoteku objavljujem na kraju posta.

20130424_095628

20130424_100501

20130424_094223

20130423_192036

20130422_214523

20130422_191850

20130422_191736

20130422_165302

Oktobarski sastanak Bihac .NET UG


Termin sastanka: 31. 10. 2012. 17:00, Tehnički fakultet Bihać

Nakon ljetnje pauze i septembaskih obaveza zakazujemo naredni sastanak Bihac .NET UG. Naime, u srijedu 31. oktobra sastaćemo se na starom mjestu, na Tehničkom fakultetu u Bihaću i održati sastanak na temu razvoja Windows 8 aplikacija. Ovog puta moja malenkost će održati predavanje pod nazivom “Consuming data in Windows 8 Store apps” u narednom tekstu date su detaljne informacije o predavanju.

Tema: Consuming data in Windows 8 Store app / Konzumacija podataka u Windows 8 Store aplikacijama

Level: 300

Predavač: Bahrudin Hrnjica, Microsoft MVP

Opis: Windows 8 Store aplikacije izvršavaju se u izoliranom okruženju kojim upravlja Windows Run-Time. Ova okolina pruža mogućnosti razvoja aplikacija pod nazivom Windows Store app, odnosno novi tip aplikacija koje se vrte na Windows 8 OS. Jedna od karakteristika ovih aplikacija je što su prilagođene za pokretanje na raznim uređajima od notebooka, tableta do PCa, i što mogu da se distribuiraju na Windows Store globalnu prodavnicu Windows 8 aplikacija. Jednistvenost platforme daje i određena ograničenja, a u ovom predavanju ćemo vidjeti na koji način Windows Store aplikacijama obezbijediti podatke iz različitih izvora podataka, a posebno sa SQL Servera. Widnows Store aplikacija nisu u mogućnosti da direktno pristupe Entity Framework ORM maperima, pa smo prisiljeni da koristimo ili ASP.NET Web API ili WCF. Demo primjeri će pokazati kako koristiti HTTPClient klasu za pristup podacima preko pomenutih serverskih tehnolgija. S druge strane na predavanju će biti pokazano kako koristiti SQLite C++-cross-platform biblioteku u Windows Store applikacijama direktno bez korištenja pomenutih Rest i WCF tehnologije. Kroz demo primjere predavanje će dati kompletnu sliku kako Windows Store aplikacija mogu koristiti podatke iz vanjskih izvora bez kojih je teško zamisliti današnju modernu Windows 8 Store aplikaciju.

Na sastanku će biti i nekoliko nagrada na najsretnije i najaktivnije članove. Nagrade su: majica, usb stik, …..

Developing Windows Store App Part 1: Database Model


This is the first of several blog posts about developing Windows 8 Store app. The first blog post will show how to implement database model which will be used in our application. If you want to get more information about the application we are developing please see the previous announcment post. Before we start with the tutorial, several requirements must be satisfied:

1. You need to have installed at least Visual Studio 2012 Express

2. You need to have at least SQL Server 2008 or 2012 Express.

Our database model is very simple. We have three tables: Places, Dishes and Towns. Relation of those tables shows the picture below.

SQL database will also be provided by the end of the blog post. Now that we have database model on the paper, we can start with implementation. We will use Entity Framework 5, and Code First technology in order to implement db model.
Start Visual Studio 2012, choose File->New->Project. Choose ClassLibrary similar as picture below.

After we created the empty Class Library project, we can start with implementation of the entities. According to db model shoed earlier, we are going to create three .NET classes: Dish, Town, Place. In order to do that:

  • Right Click at the Project
  • Add New Class
  • Give name: Dish

Repeat the process for Town and Place. Text below shows the implementation of classes.
Town class:

public partial class Town
{
public int? TownID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Image { get; set; }
//relation 0-oo
//many places can be in one Town
public ICollection Places { get; set; }
}

Dish class:

public partial class Dish
{
    public int? DishID { get; set; }
    public string Name { get; set; }
    public string Slogan { get; set; }
    public string Description { get; set; }
    public string Image { get; set; }
    //relation 0-oo
    //many places can have one dish
    public ICollection<Place> Places { get; set; }
}

Place class:

public partial class Place
{
    public int? PlaceID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public int? DishID { get; set; }
    public string Slogan { get; set; }
    public string Type { get; set; }
    public int? TownID { get; set; }
    public string Image { get; set; }
    //one relation to Dish
    public Dish PlaceDish { get; set; }
    //one relation to Dish
    public Town PlaceTown { get; set; }
}

Since we are using Code First, we need to specify the relation between entities too. That’s why we have put the last two properties in Place class, and also IColletion property of the previos classes. This is enough information that Code First make relation between tables on SQL Server.  By default PlaceID is primary key for Place table, as well as DishId and TownID for corresponded tables.
Now that we have entities, we need to implement DBContex, central class for handling all operation and transaction against database. Before we implement DBContext we need to add Entity Framework reference. Since EF is separated from the .NET we can use NuGet to accomplish this.
1. Right click on Reference, choose Manage NuGet package

In Search box type: Entity Framework and hit enter. Package will appear in the list. Click Install button. Picture below shows Manage NuGet Package dialog. Accept license agreement, and close the dialog.

CExplorer DataContext class:

public class CExplorerContext: DbContext
{
    public CExplorerContext() : base("cexplorer_db")
    {
        Configuration.LazyLoadingEnabled = false;
    }

    //entity sets
    public DbSet<Place> Places { get; set; }
    public DbSet<Dish>  Dishes  { get; set; }
    public DbSet<Town>  Towns  { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        //crating one to many relation between Town and Place
        modelBuilder.Entity<Place>()
            .HasRequired(x => x.PlaceTown)
            .WithMany(d => d.Places)
            .WillCascadeOnDelete(true);

        ////crating one to many relation between Dish and Place
        modelBuilder.Entity<Place>()
            .HasRequired(x => x.PlaceDish)
            .WithMany(d=>d.Places)
            .WillCascadeOnDelete(true);

        base.OnModelCreating(modelBuilder);
    }
}

As you can see, we have overridden ModelCreation virtual method and implement relation between entities. This is classic one to many relation.

At the end of the implementation, we need to provide connection string to SQL Server, it must be with the same name as we specified in the implementation od the DBContext.

1. Add New Item: App.config file and put the following configuration.

Based on SQL instance name, change the connection string. Database could not exist on the SQL server. If there is a database on the SQL with the same name, EF will add table in to existing database.

Before we end the today’s post, lets quickly create Console Test application to make sure we implemented correct model.

1. File->New->Add New Project
2. Console Application

Like previous add Entity Framework by NuGet.
Add reference of EFModel.
Open Program.cs and put the following implementation:

class Program
{
    static void Main(string[] args)
    {

        CExplorerContext ctx = new CExplorerContext();

        var dish = new Dish() { DishID = 1, Description = "Description", Name = "DishName", Slogan = "Slogan", Image = "Default.jpg" };
        var town= new Town(){TownID=1, Name= "TownName", Description="Description", Image=""};
        ctx.Dishes.Add(dish);
        ctx.Towns.Add(town);
        ctx.SaveChanges();
        var place = new Place() { PlaceID = 1, Name = "Place Name", Description = "DEscription", Image = "default.jpg", Slogan = "Slogan title", DishID = 1, TownID = 1 };
        ctx.Places.Add(place);
        ctx.SaveChanges();

        var plc = ctx.Places.FirstOrDefault();
        Console.WriteLine("Place from Database");
        Console.WriteLine("Place from database Name:{0}", plc.Name);
        Console.Read();

    }
}

After we run, output console shows that the entities are inserted successively on database.

In other words Cexplorer_DB database is created on the SQL server, and entities are inserted from the test.

Code First approach is very powerful, we only need to specified connection string, and everything is created just like we do, in Model First approach.  Complete source code for this Demo can be found here.

MSCommunity BiH Session: Developing Windows Store LOB apps


After great 3 days of KulenDayz and CEE MVP Summit in Baranja (north-east part of Croatia), the next conference I will be speaking is MSCommunity BiH konferencija in Sarajevo.
For the first time, Microsoft Community in Bosnia and Herzegovina is organizing the event dedicated for launching new Microsoft products Windows 8, Windows Server 2012 and Visual Studio 2012. For this conference I prepared a session about developing Windows Store LOB apps. This presentation has a lot of cool demos integrated in to one app called ĆevapExplorer.
Through the session I will be presenting how to design Windows Store app, by describing main design requirements of each WinStore app. Beside design feature, Win Store app requires data and connection to data source. Through the demo it will be presenting how to develop data model by using the latest Microsoft ORM Entity Framework V5.
After DB model is implemented, we need some way to provide data to Windows Store app. Windows Store app is running in some kind of isolated storage provided by Windows Run-Time, so there is no way to connect EF model directly to Win Store app. The only way to provide EF data to Win Store app is by implementing some kind of web service (REST or WCF in our case).
The second part of the demo will be presenting how to implement WCF service by using the latest version of the .NET 4.5 and WCF 4.5. If you want to develop lighter service infrastructure, beside WCF, you can use ASP.NET Web API to implement RES service.
The further demo will be presenting how to implement REST service that will be used by Win Store app. Implementation of REST service by using ASP.NET Web API is very popular MS Technology today, and it is recommended for developing this kind of services.
After backend infrastructure is presented, the main demo can starts using data of EF Model through REST or WCF service. In the first part of the main demo it will be presenting how to develop UI for presenting data, by describing how to use predefined visual studio 2012 templates, how to use HttpClient and how to integrated our app with Windows 8, by implementing Windows 8 contracts. By implementation Search Contract, demo will show how to integrate Windows 8 Search mechanism in to our app.
As the last part of demo, it will be presenting how to implement data source without using .NET infrastructure, but using only WinRT. For this we will use SQLite library. SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. Because of native support of WinRT, this library can be easily compiled and built in Windows RunTime, so we used it as a C/C++ class library in our C# WinStore app. This part of demo present how to used native nature of WinRT to use C/C++ library in our C# application, without complex implementation seen in .NET with P/Invoke and DLL Import.

Because of importance of accepting new Windows 8 develop technology in the future development, this blog post is part of several post which will give detail information about each mentioned part of the demo. Each blog post will be describe in form of tutorial one part of the demo. The name of demo is ĆevapExplorer. Ćevap stands for the most populate Bosnian national dish which can be found in every restaurant, but only few of them serve the best Ćevap. The application is collecting data about the best restaurants around the Bosnia not only for Ćevap, but the main Bosnian dishes. The app present location about restaurants serving the best dish.
After conference event, blog post will be published periodicaly.
See you in Sarajevo.

New feature in C# 5.0 – [CallerMemberName]


By releasing the beta version of Visual Studio 11 and .NET 4.5, Microsoft has also released the new version C# 5.0. C# 5.0 brings a new programming pattern called asynchronous programming with new keyworkds async an await. I have blog posted about it previously. C# 5.0 also brings new features which accelerate development specialy when you implementing bindable properties, and need to put OnPropertyChanged with property name as an argument in each setter block.

C# 5.0 introduce [CallerMemberName] attribute which you can put as an agrument of the method. It is very strange syntax for C# but very efficient. For example:

/// <summary>
/// Notifies when the property is changed
/// </summary>
/// <param name="propertyName">New Features in C# 5, that you can easely skip writing string of property name.</param>
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
    //whatever you need to be called
}

The method above you can call in the following situation:

public string SomeProperty
{
    get
    {
        return _someProperty;
    }
    set
    {
        if (value != _someProperty)
        {
            _someProperty = value;
            //You dont need to pass string of the propertyname, compiler will do for us.
          //OnPropertyChanged("SomeProperty"); - no need any more
            OnPropertyChanged();
        }
    }
}

What hepends behind the scene is that the c# compiler resolve your property name and put on the right place. If you dont beleive  you can see the picture which has taken during the debuging:

The whole example is listed here.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace NewFeatureCsharp
{
class Program
{
    static void Main(string[] args)
    {

        SomeClass someClass = new SomeClass();

        someClass.SomeProperty = "Hello World";

        Console.ReadKey();
    }

    public static void CallAfterPropertyChanged()
    {
        Console.WriteLine("Property is changed!");
    }
}

/// <summary>
/// Class example with propertychanged
/// </summary>
public class SomeClass : INotifyPropertyChanged
{
    private string _someProperty;
    /// <summary>
    /// This is property with automatic implementation of getter and setter, but in C# 5.
    /// This is also automatic implermentation of propertychanged notification as well.
    /// </summary>
    public string SomeProperty
    {
        get
        {
            return _someProperty;
        }
        set
        {
            if (value != _someProperty)
            {
                _someProperty = value;
                //You dont need to pass string of the propertyname, compiler will do for us.
                OnPropertyChanged();
            }
        }
    }

    /// <summary>
    /// Notifies that the property is changed
    /// </summary>
    /// <param name="propertyName">New Features in C# 5, that you can easely skip writing string of property name</param>
    protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        Program.CallAfterPropertyChanged();
    }
    public event PropertyChangedEventHandler PropertyChanged;
}
}

And output result is the following:

Windows 8 Metro Tips and Tricks


Windows 8 Metro Style

It is important to know some key shortcats in order to be productive and efficient when working in Windows 8 specially in Metro style Mode. Since any Metro App does not have Exit option it is important to know how to return back or how to log off or turn off our PC.

Since there is no Exit command in Metro, applications cannot be exited in the traditional way. In fact every Metro style app has three states Active- when it is showed on screen, Suspended- when it is in background and Destroyed- when OS kill the process of your app. When other Windows 8 Metro app is launched, the previous application goes off the screen and becomes suspended. After about 5 seconds application goes to transient state. It is important to know that suspended apps are not removed from memory, but all their threads are suspended. On that way suspended application can be activated and showed on the Metro screen immediately. On the other hand suspended apps don’t consume energy or they consume energy in minimum amount. Suspended apps can be terminated of a low memory condition. This is the case when the application is relaunched as a new run. During relaunching it can be implemented so that the app can restore its state from persistent storage and appear to the user as if it has never been gone.

At the end of this blog post let’s review the shortcuts for some action in Windws 8 Metro:

  • winkey – switch between Desktop and Metro mode
  • winkey+L – Log off from the Window current session
  • winkey+F – Open Metro Search engine for searching different content: Apps, files, settings, etc
  • winkey+P – Change Monitors layout.
  • winkey+any – Starts searching for content.
  •  winkey+ESC – Back to Desktop mode (Windows 7++).
  • winkey+i –    Setting of Desktop, Power, Audio and Network.
  • winkey+o – Lock screen rotation.
  • winkey+d –  Whos Desktop mode (Windows 7++)
  • winkey+h –  Open the share charm
  • winkey+k –   Open the connect share charm
  • winkey+TAB – Toggles between opened apps
  • winkey+SPACE – Toggles input language and keyboard
  • winkey+c –   Open the “charms bar” (share, settings, shutdown)
  • Mouse RClick on App Tile – shows the App Bar with advanced option.
  • ALT+TAB – Switch between apps.
  • Press any key – Unlock screen
  • CTRL+SHIFT+ESC – force to close metro app, since there is no Exit option in app.