Category Archives: Xml

Xml

[RESOLVED]how to automatically generate my sitemap.xml

Hi, i understood that the sitemap.xml is important to be on google… than i would like to know if there is an easy script in MVC to generate it aoutomatically.

I want this because my site is a little blog and i update it daily…

another thing that i need to do is the fact that my blog is done in 4 languages ENG, FRA, ITA ESP, so i would love to know ow it works for the site map to be in 4 languages and than ow to generate it..

Thanks

Hi grafic,

As far as I know, there isn’t the script to generate the SiteMap file automatically in ASP.NET MVC.

You need do it by yourself.

There are some articles that can help you:

# Generating dynamic XML Sitemaps in ASP.NET MVC

http://benfoster.io/blog/generating-dynamic-xml-sitemaps-in-aspnet-mvc

# Dynamically create google SiteMap with ASP.NET

http://blog.divergencehosting.com/2009/04/01/dynamic-create-google-sitemap-aspnet/

Best Regards

Starain Chen

[RESOLVED]Regarding IOC & DI relation ship and the concept like inject dependencies to invert control

i admit that i really confuse between IOC & DI ? what is relation between IOC & DI ? what is container in DI ? what container does ?

How MS Meaf is similar & different than DI concept & usage ?

please discuss about IOC & DI for beginner.

what is the meaning of this line You need to inject dependencies to invert control ?

Anyone can u plzz discuss with small example to explain what you said like
inject dependencies to invert control

thanks

Hi,

IoC is a generic term meaning rather than having the application call the methods in a framework, the framework calls implementations provided by the application.

DI is a form of IoC, where implementations are passed into an object through constructors/setters/service look-ups, which the object will ‘depend’ on in order to behave correctly.

IoC without using DI, for example would be the Template pattern because the implementation can only be changed through sub-classing.

DI Frameworks are designed to make use of DI and can define interfaces (or Annotations in Java) to make it easy to pass in implementations.

IoC Containers are DI frameworks that can work outside of the programming language.  In some you can configure which implementations to use in metadata files (e.g. XML) which are less invasive.  With some you can do IoC that would normally
be impossible like inject implementation at
pointcuts
.

See also

http://martinfowler.com/articles/injection.html#InversionOfControl

Taken from

http://stackoverflow.com/questions/6550700/inversion-of-control-vs-dependency-injection

mou_inn

How MS Meaf is similar & different than DI concept & usage ?

The Managed Extensibility Framework (MEF) is a composition layer for .NET that improves the flexibility, maintainability and testability of large applications. MEF can be used for third-party plugin extensibility, or it can bring the benefits of a
loosely-coupled plugin-like architecture to regular applications. (taken from

http://mef.codeplex.com/).

Grz, Kris.

thanks for answer but it would be great if u discuss all the points with bit of example that may help me like beginner developer lots. thanks

Hi,

the best thing is to simply take a look at a DI container and its documentation and start using it. There are tutorials available on this site that show it:

Grz, Kris.

[RESOLVED]How to import Resume in Asp.net MVC

I want to import a resume like when a resume is uploaded, immediately resume content like candidate skills,experience should display on text fields like skills on skills textbox from resume, experience in experience textbox from resume. How it is possible,
can u give me some example how to do this in Asp.net mvc.

Is there any .dll to do that?

I have tried on google, but i didn’t get perfect example, please help anyone

Sanjay_Net

. How it is possible, can u give me some example how to do this in Asp.net mvc.

MVC does not read Word documents. You should try some other controls, such as ASPOSE

In addition to aspose you can try DocX (http://docx.codeplex.com/) or the XML SDK.

Reading the Word document itself is only half the issue, the other is parsing it intelligently to extract the data you need, which is not a trivial process.  People build whole businesses around what you’re trying to do, it’s unlikely you’re going to get
someone to give you industry leading code for free.  I’m sure there will be components that do this work already if you google for them.

There are some third party tools that provides the resume parsing functionality. Please take a look at these sites

http://www.sovren.com/sovren-resume-cv-parser/

http://rchilli.com/solutions/b2b-web-api/

If you don’t want to go with third party tools, then I recommend to take a look at Open XML toolkit.

http://msdn.microsoft.com/en-us/library/office/bb448854(v=office.15).aspx

Can you give some reference example using Open XML toolkit, that how it will work.

I googled "open xml sdk read word document" and here are some links, if you google yourself you’ll find a lot more

http://msdn.microsoft.com/EN-US/library/office/cc850833(v=office.15).aspx

http://justgeeks.blogspot.co.uk/2011/09/reading-ms-word-2007-document-in-docx.html

[RESOLVED]Save Error in Xml File With Elmah

I use elmah for find error . i want to save error in xml file. after i wrote Commands in cinfig file :

config file :

<elmah>
    <security allowRemoteAccess="1"/>
    <errorlog type="Elmah.XmlFilerErrorLog, Elmah" logPath="~/App_Data" />
</elmah>

How to access this xml file .is there this file in application ?

throw an error and look with fileexplorer in App_Data folder

Hi AR-Web,

Thanks for your post.

Please refer to this tutorial:

https://code.google.com/p/elmah/wiki/MVC

Maybe it will be helpful.

Best Regards,

Eileen

[RESOLVED]Newbie intern: A little lost on how to structure and get my project started (updating DB tables with an SPA)

Hi all,

So here are the details of the project that I have been assigned:

The company has several database tables which I am to make accessible via a webpage, and users that are properly authenticated should be able to go in, select the appropriate table from a drop-down and then edit the relevant row. The updates should then
be send back to the database. They already have a web project going that uses Web-Api as a backend with angular.js as a front-end, and I’d like to make mine as compatible as that so that it could eventually be integrated within. 

Initially, I thought to use strongly typed models using the ado.net data object model, but what if they want to dynamically add a new table to the list in the drop down? Would I not have to go into my code, and always explicitly add a new model to accommodate
this? Is there a way to dynamically handle any new table (perhaps by not using Entity Framework)?

If you need more details, just let me know. How would you more experienced programmers handle this?

Thanks in advance, any advice would be appreciated! :)

ZimbuTheMonkey

t what if they want to dynamically add a new table to the list in the drop down?

use DataTable. Or use plugin architecture and add dll’s to the project.

What you need is some kind of meta data driven approach, where you dynamically get the tables and their columns from the database and allow user to update them. Please see this example which is done for WPF. You can easily adopt for a web application

Dynamic Data Entry With XML Literals

Thank you, I’ll have a look.

[RESOLVED]How to store and present Key Pair Values

I’ve hit a conundrum…

I have a table with Computer Devices. you can have different types eg. PC, Server, Printers so forth..

against each Type theres values that needed to be captured.

eg. PC – typeId 1 , have RAM, HDD, CPU

      Printer – typeid 2, have IsColour, IsDuplex 

Based on the user’s selection, I want to render a partial view which holds a form to input those attributes.

How is this achieved? or can it be done any other way?

alphabeatsco

Based on the user’s selection, I want to render a partial view which holds a form to input those attributes.

with Ajax call an action that returns the correct view.

there are two common sql approaches. make a table and for for each device, which is practical if there is a finite number and you need custom markup for each device. of use a meta table (name/value). 

for name value, you would create a table that defines the attributes for a device. (device id, field id,  sort order, field caption, field type). then the view would load the rows for the device, and create a form.

to store in sql, you create a values table (instanced, device, field id, value)

if you are use a table store database instead of sql, then you just store the name/value collection.

if you are using a json database, you just build a json object (though you’d probably use a json object to store the device definition).

Yeah, I’ve taken into consideration on both strategies.

Neither of it sound easy enough.

Easier approach out of them, would probably be the table created for each device.

actually a third sql approach is to use an xml column to store the defs and values.

Is it eassy enough to query?

Eg. I want to know all devices that have HDD greater than 300gb

Hi alphabeatsco,

alphabeatsco

Is it eassy enough to query?

Eg. I want to know all devices that have HDD greater than 300gb

For this scenario, you need to have the logic to do that.

Best Regards

Starain

[RESOLVED]Culture, international settings

Hi All,

I have developed a MVC application for a client. Now the German branche of my client wants to use it as well. I am becoming issues about date and decimal formats. I have of course googled about culture, dataformat, number formating but cannot find a good,
solid working solution.

I want my application to work with datetime format, decimal format which I want to. For example. I have set it up into Dutch culture(‘nl-NL’) it should use always the dutch culture regardsless of the settings on the server / IIS / or the clients browser.
If i set it up for German culture(‘de-DE’). I want it to use always the german format, regardsless if it is running on the server with dutch locals.

I hope I asked the questions the correct way. Anybody a good tutorial, working solution about how to do this.

Best regards, Marcel

If you want to set culture for the entire application (not for german users only) then add following to the web.config

<configuration>
    <system.web>
        <globalization uiCulture="de-DE" culture="de-DE" />
    </system.web>
</configuration>

Hi,

That is what i did, but still it takes the US format for numbers/decimals. In other words. I expect it to use a (,)komma for decimals and a (.) dot for thousands seperator.

For example i have two amounts

100,21 euro (one hundered euro and 21 cents)

2100,12 euro (twentyone hundered euro and 12 cents.

what my app does is converts it to

20021 euro and 210012 euro. So it thinks there are no cents there. How can i make sure that for decimals the dots and commas are rightly set. It does not see it as european notation but as american notation.

Tnx. Marcel

Make sure that culture is not changed somewhere. E.g. put following to the view to see the output

@System.Threading.Thread.CurrentThread.CurrentCulture

You can also parse decimals using specific culture

e.g.

decimal d = Convert.ToDecimal("text", new System.Globalization.CultureInfo("de-DE"));

or

decimal d = Convert.ToDecimal("text", System.Globalization.CultureInfo.CurrentCulture); // current culture is german

step-by-step guide line for integrating Log4Net in asp.net application

i have big form where user feed data and submit. after submit a server side method call occur and from there server side method we just capture data entered by user and call 3rd part web service and provide those user data to the web service. some time web
service return error message due to send wrong data. now i want to maintain log error with entered form data and send email using  Log4Net to admin. so admin can see what data user input and what error message web service return.

i never use log4net. so first need step-by-step guide line how to incorporate in any existing web apps and later i want to know how to configure it in such way as a result when error occur then it will capture and send a automatic email to admin and save
log to db.

thanks

Please take a look at this post

Adding Log4Net to your MVC project

i have seen the url but not good because not elaborately explain each config property. so here i am asking again few question about config section for log4net.

looking for some one who can help me to understand each property usage.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <log4net>
    <appender name="DbAppender" type="log4net.Appender.ADONetAppender">
      <bufferSize value="0" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="{auto}" />
      <commandText value="INSERT INTO Log4Net ([date],[thread],[level],[logger],[message],[exception]) VALUES
         (@log_date, @thread, @log_level, @logger, @message, @exception)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%t" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="10" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%p" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="1000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%c" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%m" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
    </appender>

    <root>
      <level value="INFO" />
      <appender-ref ref="RollingFileAppender" />
      <appender-ref ref="DbAppender" />
    </root>
  </log4net>
</configuration>

please see the above config details and answer each property. 1) why

<bufferSize value="0" />

is set to 0 ? when one should set other value to

bufferSize

property ?

2)

<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

how do i know what

PublicKeyToken

value i need to use.

3) what is the meaning of connection string auto

<connectionString value="{auto}" />

?

4)

what is the meaning of conversionPattern or

5 what is ExceptionLayout

<layout type="log4net.Layout.ExceptionLayout" />

6) what is the meaning of below xml

<root>
  <level value="INFO" />
  <appender-ref ref="RollingFileAppender" />
  <appender-ref ref="DbAppender" />
</root>

what is

RollingFileAppender

? what is

DbAppender

?

please discuss about my each point & question. thanks

[RESOLVED]enable CORS MVC 5

How to work with CORS?

Two ways:

1. Adding: HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", "*");

Or 2. Adding the header through web.config:

<system.webServer>

    <httpProtocol>
      <customHeaders>
        <clear />
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>

..

Source:

http://www.c-sharpcorner.com/Blogs/11609/how-to-enable-cross-origin-resource-sharing-in-mvc.aspx

However, as a side note, you might also be interested in looking at:  CORS support for WebAPI:

https://aspnetwebstack.codeplex.com/wikipage?title=CORS%20support%20for%20ASP.NET%20Web%20API

CORS attributes (EnableCors) dynamically (i.e., at controller level):

http://blogs.msdn.com/b/webdev/archive/2013/07/02/manage-cors-policy-dynamically.aspx

Thank you. It works. What does it mean when I enable CORS?

Hi Alex,

CORS means Cross Origin Resource Sharing. It allows the communication across domains. By enabling it for our server APIs – we allow our services to have communications across the domains. By default browsers will not allow it, unless we pass set http header
explicitly.

CORS allows you to request data from another origin while message passing between main window and an iframe is used when you want to communicate with an app that is inside the iframe but is not in the same origin.

A practical example:

1.You have an iframe that has a youtube player.

2.You request some videos to play from youtube data api (CORS, could be JSONP, XHR or whatever).

3.You now pass a cross-domain message to the iframe to start playing any of the video you requested in step #2.

From Reference: http://stackoverflow.com/a/8186722

Also from WikiPedia definition:

Cross-origin resource sharing (CORS) is a mechanism that allows many resources (e.g., fonts, JavaScript, etc.) on a
web page to be requested from another
domain outside the domain from which the resource originated.[1]
In particular, JavaScript’s
AJAX
calls can use the
XMLHttpRequest
mechanism. Such "cross-domain" requests would otherwise be forbidden by

web browsers
, per the
same-origin security policy
. CORS defines a way in which the browser and the server can interact to determine whether or not to allow the cross-origin request.[2]
It is more useful than only allowing same-origin requests, but it is more secure than simply allowing all such cross-origin requests.

Reference:

http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

It also means you need to take extra care with security, as you have disabled the browsers security. You will be open to cross site scripting attacks unless you code for them.

[RESOLVED]MVC Bundling & Minification Problem

Hi, I have bundled my JS files as follows in BundleConfig.cs

bundles.Add(new ScriptBundle("~/bundles/js").Include(
               "~/js/jquery/jquery.min.js",
               "~/js/jquery/jquery.mousewheel.js",
               "~/js/jquery/jquery.widget.min.js",
               "~/js/metro.min.js",
               "~/js/prettify/prettify.js",
               "~/js/load-metro.js",
               "~/js/docs.js",
               "~/js/github.info.js"));

In my Layout I have following in head section:

@Scripts.Render("~/bundles/js")

I have a view studentdetials.cshtm in student folder which is not rendering as expected.

In the browser error console I get following 404 – not found error:

Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:1568/Student/js/metro.min.js?_=1413550048924

metro.min.js is not inside the student folder but "JS" folder which is in root of the project directory, however my view is searching it inside the student/js/ folder.

Please let me know what I am missing.

Thanks & Regards

Hi Siteslayer,

I have faced similar issue. Actually during bundling, framework manages js files.

In release mode, you will getting this error but not in debug mode, if i understood the problem correctly.

I am getting this problem in debug mode.

Hi siteslayer,

Thanks for your post.

 You can   Use the F12 Developer Tools to Debug JavaScript Errors.

Bundling and minification is enabled or disabled by setting the value of the debug  attribute in the

compilation Element

 in the Web.config file. In the following XML,debug is  set to true so bundling and minification is disabled.

<system.web>
    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
</system.web>

To enable bundling and minification, set the debug value to  "false".

public static void RegisterBundles(BundleCollection bundles)
{
    //bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));

    // Code removed for clarity.
    BundleTable.EnableOptimizations = true;
}

Hope this can be helpful.

Best Regards,

Eileen

Eileen ni – MSFT

Hi siteslayer,

Thanks for your post.

 You can   Use the F12 Developer Tools to Debug JavaScript Errors.

Bundling and minification is enabled or disabled by setting the value of the debug  attribute in the

compilation Element

 in the Web.config file. In the following XML,debug is  set to true so bundling and minification is disabled.

<system.web>
    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
</system.web>

To enable bundling and minification, set the debug value to  "false".

public static void RegisterBundles(BundleCollection bundles)
{
    //bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                 "~/Scripts/jquery-{version}.js"));

    // Code removed for clarity.
    BundleTable.EnableOptimizations = true;
}

Hope this can be helpful.

Best Regards,

Eileen

Thanks a lot Eileen, that solved the problem.