Click here to Skip to main content
15,891,033 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Get User.Identity.Name on login page Pin
AlexeiXX320-Feb-08 7:55
AlexeiXX320-Feb-08 7:55 
GeneralTextarea.Value Commit issue Pin
gavin lane20-Feb-08 0:58
gavin lane20-Feb-08 0:58 
GeneralRe: Textarea.Value Commit issue Pin
newc120-Feb-08 1:47
newc120-Feb-08 1:47 
QuestionHow to store dataview's data in a datatable Pin
dews turner20-Feb-08 0:54
dews turner20-Feb-08 0:54 
AnswerRe: How to store dataview's data in a datatable Pin
dews turner20-Feb-08 1:18
dews turner20-Feb-08 1:18 
Generalrational clear case Pin
Member 387988120-Feb-08 0:43
Member 387988120-Feb-08 0:43 
GeneralRetrieving Videos from a directory and displaying them to a user Pin
capdevillia20-Feb-08 0:40
capdevillia20-Feb-08 0:40 
Generalcustom resource provider compile time errors Pin
Member 285544920-Feb-08 0:39
Member 285544920-Feb-08 0:39 
Hi i have created custom resource provider and getting the resources from xml file...appliction is not building ... i am getting compile time errors...'the resource object with key is not found'... Plz Provide me solution... here is my code

using System;
using System.Web.Compilation;
using System.Globalization;
using System.Resources;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Xml;
using System.Web;
using System.Web.Hosting;
using System.Web.Caching;

namespace Hydra.Providers
{

public sealed class XmlResourceProviderFactory : ResourceProviderFactory
{
public static ListDictionary resourceList = new ListDictionary();
public XmlResourceProviderFactory()
{
}

public override IResourceProvider CreateGlobalResourceProvider(string classKey)
{
return new XmlResourceProvider(null, classKey);
}

public override IResourceProvider CreateLocalResourceProvider(string virtualPath)
{
//virtualPath = this.GetVirtualPath(virtualPath);
return new XmlResourceProvider(virtualPath, null);
}

public class XmlResourceProvider : IResourceProvider
{
private string _virtualPath;
private string _className;
private IDictionary _resource;
private static object CultureNeutralKey = new object();

public XmlResourceProvider(string virtualPath, string className)
{
_virtualPath = virtualPath;
_className = className;
}

//private IDictionary GetResource(string cultureName)
//{
// _resource = new ListDictionary();

// IDictionary resourceDict = _resource as IDictionary;

// resourceDict = XmlResourceHelper.GetResources(_virtualPath, _className, cultureName, true, null);
// _resource = resourceDict;

// return resourceDict;
//}



private IDictionary GetResource(string cultureName)
{

object cultureKey;
if (cultureName != null)
{
cultureKey = cultureName;
}
else
{
cultureKey = CultureNeutralKey;
}
if (_resource == null)
_resource = new ListDictionary();

IDictionary resourceDict = _resource[cultureKey] as IDictionary;
if (resourceDict == null)
{
resourceDict = XmlResourceHelper.GetResources(_virtualPath, _className, cultureName, true, null);
_resource = resourceDict;
}

return resourceDict;
}
object IResourceProvider.GetObject(string resourceKey, CultureInfo culture)
{
if (string.IsNullOrEmpty(resourceKey))
{
throw new ArgumentNullException("resourceKey");
}

if (culture == null || culture == CultureInfo.InvariantCulture)
culture = CultureInfo.CurrentUICulture;

object value = GetResource(culture.Name)[resourceKey];

return value;
}





public System.Resources.IResourceReader ResourceReader
{
get
{
return new XmlResourceReader(GetResource(null));
}
}
}

private sealed class XmlResourceReader : IResourceReader
{
private IDictionary _resources;

public XmlResourceReader(IDictionary resources)
{
_resources = resources;
}

IDictionaryEnumerator IResourceReader.GetEnumerator()
{
return _resources.GetEnumerator();
}

void IResourceReader.Close()
{
}

IEnumerator IEnumerable.GetEnumerator()
{
return _resources.GetEnumerator();
}

void IDisposable.Dispose()
{
}
}

internal static class XmlResourceHelper
{
public static IDictionary GetResources(string virtualPath, string className, string cultureName, bool designMode, IServiceProvider serviceProvider)
{
//ListDictionary resources = new ListDictionary();
string xmlFilePath;
string strCompanyId = "1";
//string strLayoutId = "1";
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string aspxPage = oInfo.Name;
string[] aspxPage1 = aspxPage.Split('.');
//HttpContext.Current.Handler
object obj = HttpContext.Current.Request;


//try
//{
// if (HttpContext.Current.Session["CompanyId"] != null)
// strCompanyId = HttpContext.Current.Session["CompanyId"].ToString();

// if (HttpContext.Current.Session["LayoutId"] != null)
// strLayoutId = HttpContext.Current.Session["LayoutId"].ToString();
//}
//catch {}

if (!String.IsNullOrEmpty(virtualPath))
{

// Get Local resources
XmlDocument configurationFile = new XmlDocument();
// xmlFilePath = HostingEnvironment.MapPath(HostingEnvironment.ApplicationVirtualPath + "/Languages/Local/" + strCompanyId + "/" + strLayoutId + "_en-US.xml");
xmlFilePath = HostingEnvironment.MapPath(HostingEnvironment.ApplicationVirtualPath + "/Languages/Local/" + strCompanyId + "/" + aspxPage1[0].ToLower() + "_en-US.xml");

//configurationFile.Load(xmlFilePath);

XmlReader reader;
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
reader = XmlReader.Create(xmlFilePath, settings);
reader.Read();
configurationFile.Load(reader);
XmlNode node = configurationFile.DocumentElement;
parseResourcefile(node);

}
else if (!String.IsNullOrEmpty(className))
{
// Get Global resources
XmlDocument configurationFile = new XmlDocument();
// xmlFilePath = HostingEnvironment.MapPath(HostingEnvironment.ApplicationVirtualPath + "/Languages/Local/" + strCompanyId + "/" + className + "_en-US.xml");
xmlFilePath = HostingEnvironment.MapPath(HostingEnvironment.ApplicationVirtualPath + "/Languages/Local/" + strCompanyId + "/" + aspxPage1[0].ToLower() +"_en-US.xml");
configurationFile.Load(xmlFilePath);
XmlNode node = configurationFile.DocumentElement;
parseResourcefile(node);
}
return resourceList;
}
public static void parseResourcefile(XmlNode node)
{

foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.Name.StartsWith("resources"))
{
parseResourcefile(childNode);
}
else
{
if (childNode.Attributes["name"] != null && childNode.InnerText != string.Empty)
{
string rn = childNode.Attributes.Item(0).Value.ToString();
string rv = childNode.InnerText.ToString();
if (!resourceList.Contains(rn))
{
resourceList.Add(rn, rv);
}

}
}
}

}
}
}
}
GeneralDisplay values from dataset to textboxes.. Pin
codingrocks20-Feb-08 0:34
codingrocks20-Feb-08 0:34 
GeneralRe: Display values from dataset to textboxes.. Pin
That's Aragon20-Feb-08 1:26
That's Aragon20-Feb-08 1:26 
Generalopening a new browser window from gridview hyperlinkfield Pin
eyeseetee20-Feb-08 0:15
eyeseetee20-Feb-08 0:15 
GeneralRich TextBox in ASP.NET Pin
.NET- India 19-Feb-08 23:51
.NET- India 19-Feb-08 23:51 
GeneralRe: Rich TextBox in ASP.NET Pin
N a v a n e e t h19-Feb-08 23:57
N a v a n e e t h19-Feb-08 23:57 
GeneralAJAX Panel control Pin
eyeseetee19-Feb-08 23:40
eyeseetee19-Feb-08 23:40 
GeneralRe: AJAX Panel control Pin
newc120-Feb-08 2:05
newc120-Feb-08 2:05 
GeneralSkelta in .net Pin
saravanan0519-Feb-08 23:12
saravanan0519-Feb-08 23:12 
Questionplz help me..... in gridview Pin
sri_ashutosh19-Feb-08 23:08
sri_ashutosh19-Feb-08 23:08 
AnswerRe: plz help me..... in gridview Pin
Sonia Gupta19-Feb-08 23:13
Sonia Gupta19-Feb-08 23:13 
GeneralRe: plz help me..... in gridview Pin
kiran_prakash20-Feb-08 1:23
kiran_prakash20-Feb-08 1:23 
Questionform management Pin
Sonia Gupta19-Feb-08 22:59
Sonia Gupta19-Feb-08 22:59 
GeneralRe: form management Pin
N a v a n e e t h19-Feb-08 23:19
N a v a n e e t h19-Feb-08 23:19 
QuestionRe: form management [modified] Pin
Sonia Gupta19-Feb-08 23:55
Sonia Gupta19-Feb-08 23:55 
GeneralRe: form management Pin
N a v a n e e t h20-Feb-08 0:18
N a v a n e e t h20-Feb-08 0:18 
QuestionRe: form management Pin
Sonia Gupta20-Feb-08 0:23
Sonia Gupta20-Feb-08 0:23 
QuestionRe: form management Pin
Sonia Gupta20-Feb-08 1:14
Sonia Gupta20-Feb-08 1:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.