I want to change the lang between english and arabic using webforms and ASP.NET . I already created 2 resource files and added them to assembly.
I tried to implement this code:
protected void ddLang_SelectedIndexChanged(object sender, EventArgs e)
{
Session["Lang"] = ddLang.SelectedValue;
loadString();
}
private void loadString()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Lang"].ToString());
rm = new ResourceManager("WebPortal2020.App_GlobalResources.Lang", Assembly.GetExecutingAssembly()); //we configure resource manages for mapping with resource files in App_GlobalResources folder.
ci = Thread.CurrentThread.CurrentCulture;
LblDashboard.Text = rm.GetString("Dashboard", ci); //Name is the resource manager string name that should mathch with Name solumn of resorce files and if that matches then the value against the name will be translated as mentioned for each languages.
}
andf i defined the Dashboard key in both eng and arabic rscr file.
Bu ti am getting this error :
Related
For installation using .NET, I wish to give write permission to a particular file in the folder using cacls.exe, so I have referred How to give Read/Write permissions to a Folder during installation using .NET and I have used the code from Setting File or Directory permissions ACE entries with .NET using CACLS.EXE.
After installation, on form load, I could read the file file.txt which is located at C:\Program Files\MyCompany\MyProduct , with below code:
private void Form1_Load(object sender, EventArgs e)
{
//Some code
DirectoryPermission dp = new
DirectoryPermission(filename, "Everyone", "F");
dp.SetAce();
foffset = read_file();
}
string filename = "file.txt";
private double read_file()
{
double value = 0;
try
{
value = Double.Parse(System.IO.File.ReadAllText(#filename));
return value;
}
catch
{
System.IO.File.WriteAllText(#filename, value.ToString());
return 0;
}
}
But on a button click I couldn't write the file with new value, so I wrote the below code and did installation, still the problem persist:
private void button1_Click(object sender, EventArgs e)
{
try{
DirectoryPermission dp = new
DirectoryPermission(filename , "Everyone", "F");
dp.SetAce();
System.IO.File.WriteAllText(#filename , offset.ToString());
}
catch
{}
}
I'm giving full control to all the users, but I'm not able to write the file. and I'm getting this error
Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.dll
Please help me in this.
The code that you see was taken from MSDN. Upon testing it says invalid path for SOURCE. I agree. They want the source to be a URL in another Reporting Server. However what I need is to be able to copy a RDL file from my C:\ to the Reporting Server. How can I ?
static void move_report(string currentPath, string targetPath )
{
ReportingService2010 service = new ReportingService2010();
ReportingService2010 rs = new ReportingService2010();
rs.Url = "http://MHPDW2/ReportServer/" + "ReportService2010.asmx";
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
rs.MoveItem(currentPath, targetPath);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.OuterXml);
}
}
static void Main(string[] args)
{
string currentPath = "H:\\ITTFS2012\\SSRS\\DW15Reports\\Claims\\6.1 universe.rdl";
string targetPath = "http://MHPDW2/ReportServer/MidwestHealthPlan/Claims/HPMS/MCR Plan Code/H5685 2014 HPMS/";
move_report(currentPath,targetPath);
What does "H:\" drive resolve to and do you have access to the source location?
Team:
I found the answer. Everything is here ( including code )
I had to use the rs.CreateCatalogItem method.
https://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.createcatalogitem.aspx
Well, I'm making a simple winform to create a text file containing paths to various songs. It's just a simplistic playlist for a visualizer/audio player that I've been working on (using XNA, C#, and Bass.Net). I'd like to use TagLib access and display song titles, artists, and to sort playlists.
This is the code that I've been using:
private void button1_Click(object sender, EventArgs e)
{
selectPlaylist.ShowDialog();
string filePath = string.Empty;
if (selectPlaylist.FileName.EndsWith(".txt"))
{
StreamReader fInput = new StreamReader(selectPlaylist.FileName);
playlistName = fInput.ReadLine();
playlistNameTextBox.Text = playlistName;
while (!fInput.EndOfStream)
{
filePath = fInput.ReadLine();
if (!filePath.Contains(":\\")) continue;
songInfo.Add(TagLib.File.Create(filePath).Tag); //List<TagLib.Tag>
songs.Add(filePath); //List<string>
}
songNamesComboBox.DataSource = songs;
fInput.Close();
fInput = null; //don't even know if I need this
}
}
Regardless of what files I use, all of the Tag properties/attributes are empty. I created a console application and did the same thing (creating a file and saving its Tag to a variable) and was able to correctly access tag information.
TagLib.Tag tag = TabLib.File.Create("D:\\Music\\Electronic Music\\" +
"Instrumental Core\\The Angels Among Demons.mp3").Tag;
Console.WriteLine(tag.Title);
I'm a bit new to C#, but I cannot figure what I've done wrong. Why would the latter (console application) work, but not my winform?
I am working on localization and pulling all the available cultures based on the folders created in bin. the name of the folders are then converted into culturesInfo.
if (!bFoundInstalledCultures)
{
//determine which cultures are available to this application
Debug.WriteLine("Get Installed cultures:");
CultureInfo tCulture = new CultureInfo("");
foreach (string dir in Directory.GetDirectories(Application.StartupPath))
{
try
{
//see if this directory corresponds to a valid culture name
DirectoryInfo dirinfo = new DirectoryInfo(dir);
tCulture = CultureInfo.GetCultureInfo(dirinfo.Name);
//determine if a resources dll exists in this directory that matches the executable name
if (dirinfo.GetFiles(Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".resources.dll").Length > 0)
{
pSupportedCultures.Add(tCulture);
Debug.WriteLine(string.Format(" Found Culture: {0} [{1}]", tCulture.DisplayName, tCulture.Name));
}
}
catch(ArgumentException e) //ignore exceptions generated for any unrelated directories in the bin folder
{
}
}
bFoundInstalledCultures = true;
Above code is part of one Runtime localization example on Codeproject.com
are there are any methods thru which we can get this Info and can we use reflection.
Thanks in advance
You can use CultureInfo.GetCultures to get all installed cultures:
//create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the
//cultures installed with the .Net Framework
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
//loop through all the cultures found
foreach (CultureInfo culture in cultures)
{
// ...
}
I've already wrote my code with my try catch and extra message box but now i have to put the message box into a resource file how can i do it?
This is my code:
public void btnUpload_Click(object sender, EventArgs e)
{
try
{
// in the filepath variable we are going to put the path file that we browsed.
filepath = txtPath.Text;
if (filepath == string.Empty)
{
MessageBox.Show("No file selected. Click browse and select your designated file.");
}
}
You can just add those messages as String in your main application Resource file using the designer (Resources.resx) and then access them using Properties namespace. Let's say you add this:
ErrorNoFile | "No file selected. Click browse and select your designated file."
You can just call it like so:
MessageBox.Show(Properties.Resources.ErrorNoFile);
And if you modify the entry name in the resource file, it will be automatically refactored, at least with VS2012 which is the one I'm using. Instanciating a ResourceManager is only good if you want to keep those messages in a separate resource, otherwise it looks like an overkill to me.
// Create a resource manager to retrieve resources.
ResourceManager rm = new ResourceManager("items", Assembly.GetExecutingAssembly());
// Retrieve the value of the string resource named "filepath".
// The resource manager will retrieve the value of the
// localized resource using the caller's current culture setting.
public void btnUpload_Click(object sender, EventArgs e)
{
try
{
// in the filepath variable we are going to put the path file that we browsed.
filepath = txtPath.Text;
if (filepath == string.Empty)
{
String str = rm.GetString("welcome");
MessageBox.Show(str);
}
}