Sunday 19 February 2017

0x800a1391 - JavaScript runtime error: 'ko' is undefined

Error: 0x800a1391 - JavaScript runtime error: 'ko' is undefined

Solution:
Add KnockOut Js reference.
Ex:
@section scripts {
<script type='text/javascript' src='/Scripts/knockout-2.2.1.js'></script>

<script>
//Your code...
</script?

}

Wednesday 15 February 2017

retrieving the com class factory for component with clsid failed due to the following error asp net



Solution:
Open the project in VS
Right click on project
Select properties
In the Build tab - platform target =Any CPU

if above is not working, try below..

Exact error for me:
Retrieving the COM class factory for component
with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following er
ror: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_
SERVER_EXEC_FAILURE)).
Job Completed
Press any key to continue to close...



Error:

Retrieving the COM class factory for component
with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040153 Invalid value for registry (Exception from HRESULT: 0x80040153 (RE
GDB_E_INVALIDVALUE)).

Solution: 
Go to Run
Type: regedit
Go to this path: HKey_Classes_Root\Wow6432Node\CLSID\[GUID]
Mine is: HKey_Classes_Root\Wow6432Node\CLSID\[0006F03A-0000-0000-C000-000000000046]
Select "0006F03A-0000-0000-C000-000000000046"
Click on Right side pane
Right click "New" -->String Value
Name it: AppID
Value data: 0006F03A-0000-0000-C000-000000000046 (COM object GUID, which u got in above steps)

Right click "New" -->String Value
Name it: DllSurrogate
Value data:

Go to this path: HKey_Local_Machine\Software\Classes\AppID
Search for "0006F03A-0000-0000-C000-000000000046", if it is there don't do anything.
if you don't find it then..
Right click on -->New -->Key
Enter : 0006F03A-0000-0000-C000-000000000046



Error Message:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0×80070005 (E_ACCESSDENIED)).
Solution:

This is a COM permissions problem.

Start > Run > dcomcnfg (or “mmc -32″ and then add the Component Services snap-in manually if you can’t find the app under step 3)
Navigate to Component Services > Computers > My Computer > DCOM Config
Locate the MS application giving you trouble (eg: “Microsoft Outlook Application” )
Right click > Properties
On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
Add the account under which the site is running (eg: Network Service or Everyone) and assign Local Launch & Local Activation permissions

C# Interface

What is Interface in C#?
A) It is as simple as Class with out implementation. Only declaration of the events, methods, properties, mean .
All the methods and events which are there in interface should be inherited in  the class and should be implemented for each members in the interface.


Why Interface in C#?
A) in .Net we can't do multiple inheritance.
Ex:

class Honda
{
    //Honda Relations--Members
}

class Toyota{
    //Toyota Relations--Members
}

class
 myCarHonda,Toyota //Multiple Inheritance

{
    //Accessing both Relations class members.}

When you compile above code, we will get error.
Class " "cannot have multiple base classes: ".....Honda" and "Toyota"

The reason was .Net doesn't support multiple inheritance


So Interface is the option for multiple inheritance

Ex:
 ODDEVEN.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InterFaceDemo
{
    interface IOne
    {
        void ONE();//Pure Abstract Method Signature
    }
    interface ITwo
    {
        void TWO();
    }
    interface IThree:IOne
    {
        void THREE();
    }
    interface IFour
    {
        void FOUR();
    }
    interface IFive:IThree
    {
        void FIVE();
    }
    interface IEVEN:ITwo,IFour
    {

    }
    class ODDEVEN:IEVEN,IFive//Must Implement all the abstract method, in Derived class.
    {
        public void ONE()//Implementation of Abstract Method.
        {
            Console.WriteLine("This is ONE");
        }
        public void TWO()
        {
            Console.WriteLine("This is TWO");
        }
        public void THREE()
        {
            Console.WriteLine("This is THERE");
        }
        public void FOUR()
        {
            Console.WriteLine("This is FOUR");
        }
        public void FIVE()
        {
            Console.WriteLine("This is FIVE");
        }

    }
}

Program.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InterFaceDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This is ODD");
            IFive obj1 = new ODDEVEN();
            obj1.ONE();
            obj1.THREE();
            obj1.FIVE();


            Console.WriteLine("\n\nThis is EVEN");
            IEVEN obj2 = new ODDEVEN();
            obj2.TWO();
            obj2.FOUR();


            Console.ReadLine();
        }
    }
}
-----------------

//if( System.Diagnostics.Debugger.Launch() ) System.Diagnostics.Debugger.Break();
        var externalOwner = this.getProperty("external_owner");
        if (!string.IsNullOrEmpty(externalOwner) && externalOwner == "Aras.Document.MS-Office")
        {
            string partId = this.getID();
            try
            {
                IExcelReader excelReader = new ExcelReader(new DataAccessLayer(this.getInnovator()), new ExcelManager());
                excelReader.Extract(partId);
            }
            catch (Exception ex)
            {
                return this.getInnovator().newError(string.Format(CultureInfo.InvariantCulture, "Error occured while reading of excel file. Message: {0}", ex.Message));
            }
            finally
            {

            }
        }
        return this;
    }

    // IExcelApi is added to support unit testing
    internal interface IExcelManager
    {
        List<ExcelDataSet> ReadSheetViaDefindNames(string fname);
    }

    internal class ExcelManager : IExcelManager
    {
        public List<ExcelDataSet> ReadSheetViaDefindNames(string fname)
        {
            var data = new List<ExcelDataSet>();
            using (DocumentFormat.OpenXml.Packaging.SpreadsheetDocument doc = DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(fname, false))
            {
                data = this.Read(doc);
            }
            return data;
        }
        private List<ExcelDataSet> Read(DocumentFormat.OpenXml.Packaging.SpreadsheetDocument doc)
        {
            var data = new List<ExcelDataSet>();

            var definedNames = GetDefinedNames(doc.WorkbookPart);

            foreach (DefinedNameVal definedName in definedNames)
            {
                var worksheetPart = GetWorkSheetPart(doc.WorkbookPart, definedName);
                var cellValue = GetCellValue(worksheetPart, doc.WorkbookPart.SharedStringTablePart, definedName.StartColumn, definedName.StartRow);

                data.Add(new ExcelDataSet { Name = definedName.Key, DisplayText = cellValue });
            }
            return data;
        }
        private List<DefinedNameVal> GetDefinedNames(DocumentFormat.OpenXml.Packaging.WorkbookPart workbookPart)
        {
            List<DefinedNameVal> definedNames = new List<DefinedNameVal>();
            foreach (DocumentFormat.OpenXml.Spreadsheet.DefinedName name in workbookPart.Workbook.GetFirstChild<DocumentFormat.OpenXml.Spreadsheet.DefinedNames>())
            {
                //Parse defined name string…
                string key = name.Name;
                string reference = name.InnerText;
                string sheetName = reference.Split('!')[0];
                sheetName = sheetName.Trim('\"');

                //Assumption: None of my defined names are relative defined names (i.e. A1)
                string range = reference.Split('!')[1];
                string[] rangeArray = range.Split('$');
                string startCol = rangeArray[1];
                string startRow = rangeArray[2].TrimEnd(':');
                string endCol = null;
                string endRow = null;

                if (rangeArray.Length > 3)
                {
                    endCol = rangeArray[3];
                    endRow = rangeArray[4];
                }

                definedNames.Add(new DefinedNameVal()
                {
                    Key = key,
                    SheetName = sheetName,
                    StartColumn = startCol,
                    StartRow = startRow,
                    EndColumn = endCol,
                    EndRow = endRow
                });
            }
            return definedNames;
        }
        private DocumentFormat.OpenXml.Packaging.WorksheetPart GetWorkSheetPart(DocumentFormat.OpenXml.Packaging.WorkbookPart workbookPart, DefinedNameVal definedName)
        {
            //get worksheet based on defined name
            string relId = workbookPart.Workbook.Descendants<DocumentFormat.OpenXml.Spreadsheet.Sheet>()
                            .Where(s => definedName.SheetName.Equals(s.Name))
                            .First()
                            .Id;
            return (DocumentFormat.OpenXml.Packaging.WorksheetPart)workbookPart.GetPartById(relId);
        }
        private string GetCellValue(DocumentFormat.OpenXml.Packaging.WorksheetPart worksheetPart, DocumentFormat.OpenXml.Packaging.SharedStringTablePart stringTablePart, string startCol, string startRow)
        {
            string reference = startCol + startRow;
            //get exact cell based on reference
            DocumentFormat.OpenXml.Spreadsheet.Cell cell = worksheetPart.Worksheet.Descendants<DocumentFormat.OpenXml.Spreadsheet.Cell>()
                       .Where(c => reference.Equals(c.CellReference))
                       .FirstOrDefault();
            if (null == cell)
                return "";
            return GetValue(cell, stringTablePart);

        }
        private string GetValue(DocumentFormat.OpenXml.Spreadsheet.Cell cell, DocumentFormat.OpenXml.Packaging.SharedStringTablePart stringTablePart)
        {
            if (cell.ChildElements.Count == 0)
                return null;
            //get cell value
            string value = cell.CellValue.InnerText;
            //Look up real value from shared string table
            if ((cell.DataType != null) && (cell.DataType == DocumentFormat.OpenXml.Spreadsheet.CellValues.SharedString))
                value = stringTablePart.SharedStringTable.ChildElements[Int32.Parse(value)].InnerText;
            return value;
        }
    }
    internal class DefinedNameVal
    {
        public string Key { get; set; }
        public string SheetName { get; set; }
        public string StartColumn { get; set; }
        public string StartRow { get; set; }
        public string EndColumn { get; set; }
        public string EndRow { get; set; }
    }

    internal class ExcelDataSet
    {
        public string Name { get; set; }
        public string DisplayText { get; set; }
        public string Type { get; set; }
    }
    internal interface IExcelReader
    {
        void Extract(string partId);
    }
    internal class ExcelReader : IExcelReader
    {
        private IDataAccessLayer _dataAccessLayer;
        private IExcelManager _excelManager;

        public ExcelReader(IDataAccessLayer dataAccessLayer, IExcelManager excelManager)
        {
            _dataAccessLayer = dataAccessLayer;
            _excelManager = excelManager;
        }
        public void Extract(string partId)
        {
            string tempFolder = "", excelFilePath = "";
            try
            {
                string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                Directory.CreateDirectory(tempDirectory);
                tempFolder = tempDirectory;

                //Read the file content
                string aml = "<Item action='get' type='Part File'>" +
                             "  <source_id>" + partId + "</source_id>" +
                             "</Item>";

                var partFiles = _dataAccessLayer.applyAML(string.Format("<AML>{0}</AML>", aml));
                if (partFiles.getItemCount() == 0)//there is no file available
                    return;

                var partExcelFile = partFiles.getItemByIndex(0).getRelatedItem();
                partExcelFile.checkout(tempFolder);

                //fetch data from excel
                excelFilePath = Path.Combine(tempFolder, partExcelFile.getProperty("filename"));
                var data = _excelManager.ReadSheetViaDefindNames(excelFilePath);

                //update the part properties          
                UpdatePartProperties(data, partId);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (File.Exists(excelFilePath))
                    File.Delete(excelFilePath);
                if (Directory.Exists(tempFolder))
                    Directory.Delete(tempFolder);
            }
        }
        private void UpdatePartProperties(List<ExcelDataSet> dataSet, string partId)
        {
            string partPropertyStartTemplate = "<Item type='Part Item Characteristic Value' id='{0}' action='edit'>";
            string itemCharIdTemplate = "<item_characteristic_id>{0}</item_characteristic_id>";
            string displayTextTemplate = "<display_value>{0}</display_value>";
            string propertyTypeTemplate = "<item_characteristic_value_type>{0}</item_characteristic_value_type>";
            string partPropertyEndTemplate = "</Item>";
            string aml = "<Item action='get' type='Part Item Characteristic Value' select='item_characteristic_name,item_characteristic_value_type,item_characteristic_id'>" +
                        "<source_id>" + partId + "</source_id>" +
                        "</Item>";

            var partProperties = _dataAccessLayer.applyAML(string.Format("<AML>{0}</AML>", aml));
            int itemCount = partProperties.getItemCount();

            for (int i = 0; i < itemCount; i++)
            {
                //get the part property
                var partProperty = partProperties.getItemByIndex(i);
                //extract the values
                var itemCharName = partProperty.getProperty("item_characteristic_name");
                var itemCharType = partProperty.getProperty("item_characteristic_value_type");
                var itemCharId = partProperty.getProperty("item_characteristic_id");

                var charName = itemCharName.Replace(" ", "");
                var excelData = dataSet.FirstOrDefault(ds => ds.Name == charName);
                if (null == excelData)
                    continue;

                StringBuilder builder = new StringBuilder();
                builder.Append(string.Format(partPropertyStartTemplate, partProperty.getID()));
                builder.Append(string.Format(itemCharIdTemplate, itemCharId));
                builder.Append(string.Format(displayTextTemplate, excelData.DisplayText));
                builder.Append(string.Format(propertyTypeTemplate, itemCharType));
                builder.Append(partPropertyEndTemplate);

                var result = _dataAccessLayer.applyAML(string.Format("<AML>{0}</AML>", builder.ToString()));

                if (result.isError())
                {
                    throw new Exception("Unable to update the part properties relationships");
                }
            }
        }
    }
    internal interface IDataAccessLayer
    {
        Item apply(Item itemToApply);
        Item applyAML(string amlToApply);
    }

    internal class DataAccessLayer : IDataAccessLayer
    {
        private Innovator _inn;

        public DataAccessLayer(Innovator innovator)
        {
            _inn = innovator;
        }
        public Item apply(Item itemToApply)
        {
            return itemToApply.apply();
        }
        public Item applyAML(string amlToApply)
        {
            return _inn.applyAML(amlToApply);
        }
    }

    #region MethodFooter
    public void func(
                IServerConnection InnovatorServerASP,
                XmlDocument inDom,

                XmlDocument outDom
                )
    {
    #endregion

Monday 13 February 2017

Exporting App Pools and Websites configuration between multiple IIS instances

Open CMD
Go to this path: C:\Windows\System32\inetsrv
To get AppPool settings
Type: appcmd list apppool /config /xml > c:\apppools.xml

To get WebSite settings
Type: appcmd list site /config /xml > c:\websites.xml

Sunday 12 February 2017

MVC what is the difference between TextBox and TextBoxFor

  • @Html.TextBox() is loosely typed method whereas @Html.TextBoxFor() is a strongly typed (generic) extension method.
  • TextBox() requires property name as string parameter where as TextBoxFor() requires lambda expression as a parameter.
  • TextBox doesn't give you compile time error if you have specified wrong property name. It will throw run time exception.
  • TextBoxFor is generic method so it will give you compile time error if you have specified wrong property name or property name changes. (Provided view is not compile at run time. )

Thursday 9 February 2017

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:

Module
   IIS Web Core
Notification
   BeginRequest
Handler
   Not yet determined
Error Code
   0x80070021
Config Error
   This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Config File
   \\?\C:\Program Files (x86)\MyProject\home\web.config
Requested URL
Physical Path
   C:\Program Files (x86)\MyProject\
Logon Method
   Not yet determined
Logon User
   Not yet determined

Config Source:

    3:   <system.webServer>
    4:     <handlers accessPolicy="Read, Script" />
    5:     <directoryBrowse enabled="false" />

More Information:


Solution:

·         Open Control Panel
·         Click on "Turn windows features on or off"
·         Check "Internet Information Services"
·         Check "World Wide Web Services"
·         Check "Application Development Features"
·         Enable all items under this

Sunday 5 February 2017

The server could not complete your request. For more specific information, click the "Details" button.

The server could not complete your request. For more specific information, click the "Details" button
"Object moved" Error message when you connect to a SharePoint site by using SharePoint Designer 2013
When i try to open SPO site using SPD i got this error...
The server could not complete your request. For more specific information, click the "Details" button.
Object moved
Root Cause: In IIS anonymous authentication for the SharePoint web application that hosts the SharePoint site is disabled.
Solution:
In IIS enable anonymous authentication for the SharePoint web application.