I know this has been answered elsewhere, but I can't get the basics to run...
Regardless of the application purpose (which is obvious)
private void btnSave_Click(object sender, EventArgs e)
{
// these are *internal* properties of the NET appilcation
FileSystemWatcher.Properties.Settings.Default.MailServer = Convert.ToString(txtMailServer);
FileSystemWatcher.Properties.Settings.Default.ServerPort = Convert.ToInt16(txtServerPort.Text);
FileSystemWatcher.Properties.Settings.Default.Subject = Convert.ToString(txtSubject);
FileSystemWatcher.Properties.Settings.Default.MessageFrom = Convert.ToString(txtMessageFrom);
FileSystemWatcher.Properties.Settings.Default.MessageTo = Convert.ToString(txtMessageTo);
FileSystemWatcher.Properties.Settings.Default.Save();
}
First issue is that I get a bunch of these exceptions when I hit this code...
Exception thrown: 'System.Security.SecurityException' in mscorlib.dll
No other runtime errors I can see...
The app.config appears to be structured correctly - using Project-Add New Item.. etc and inspecting the app.config contents.
But the SAVE function listed above - doesn't save any changes I may make.
thanks
I discovered my folly... BEFORE I even knew there was a FileSystemWatcher class - I had already named my project ... you guessed it.. FileSystemWatcher !
So the namespace assumed I was talking about the class - not the app framework !
No compile errors of course!
THANKS to all the helpers!
Forgive me - I'm learning!
Related
I used to work on an Android/Xamarin project for Android 4.4, API Level 19 that contains an activity with the following code:
private void RadioButtonClick(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
switch (rb.Id)
{
case Resource.Id.radioButton1:
...
The last time I looked at the project a couple of month ago, this used to work just fine. Now I want to continue working on the project for Android 8.0, API Level 26, but when I opened it in Visual Studio 2017 I got the compiler error (field)int ResourceId.RadioButton1 A constant value is expected.
Now this is not a problem in itself, as I can always use if (rb.Id == ...) instead of switch/case, but I would like to know why all of a sudden Resource.Id.radioButton1 is not recognized as a constant anymore, even though it is declared as such in Resource.Designer.cs:
public const int radioButton1 = 2131165244;
Has anyone else encountered something similar?
EDIT: Even stranger is that the project builds without complaint, but deployment is not possible due to the said error.
EDIT: It seems that the build process generates another Resource.Designer.cs file which is put into a folder obj\Debug\designtime. Once the file exists, the activities source code refers for the Id declarations to this new file and not to the original Resource.Designer.cs in the Resources folder.
However, all Ids in the new file are static and not const (which of course is the reason for the compiler error that prompted this question in the first place) and moreover they are all set to zero.
Are there any Android/Xamarin experts out there who can explain what is going on here? Might that even be a bug in Visual Studio 2017/Xamarin?
EDIT: Here is a link shedding some light on this topic: https://forums.xamarin.com/discussion/19369/compiling-resource-ids-static-vs-const
What I don't get is this: Why did the above code work at all considering that this problem is known since 2014?
In my WPF MVVM application I need to check if my application runs first after its installation. I had reviewed some examples in SO and in one of them - how to check whether my c# window app is running first time after installation I found the following code where the author recommended the use of UpgradeRequired:
// this must happen as soon as your program starts, before
// you do anything else with the settings
if (Properties.Settings.Default.UpgradeRequired)
{
// upgrade FIRST, before doing anything else with the settings
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
I quote here his words: "I also suggest adding a "UpgradeRequired" boolean to the settings which is by default true...." But when I try to add the same code in my App.xaml.cs file in OnStartUp event handler then the following error occured: "Settings does not contain a definition for UpgradeRequired" and UpgradeRequired was underlined with a red wavy line. I havn't faced with Properties.Settings before. So I'd like to know: Which assembly reference I should add to my application? What must I do to get access to Properties.Settings.Default.UpgradeRequired? our help would be greatly appreciated.
This not in any Assembly it's your oun custom settings. It's all explained here https://msdn.microsoft.com/en-us/library/a65txexh(v=vs.140).aspx
I use an IAutoTamper2 to colorcode relevant requests/responses to my application based on url and other information.
This is very helpful for debugging. However when someone sends me a saved .saz file, I no longer see my helpful colorcodes. How can I apply the IAutoTamper2 logic when a file is imported.
I looked at the ISessionImporter interface but you have to start from scratch. Is there a way to inherit from the default importer and add my logic that occurs in the IAutoTamper2?
I've looked at all the documentation about extensions on the telerik website but couldn't find anything relevant. Any ideas?
I figured out how to do it. There is a OnLoadSAZ event that I can use to change loaded sessions.
This is my code:
public void OnLoad()
{
FiddlerApplication.OnLoadSAZ += HandleLoadSaz;
}
private void HandleLoadSaz(object sender, FiddlerApplication.ReadSAZEventArgs e)
{
FiddlerApplication.UI.lvSessions.BeginUpdate();
foreach (var session in e.arrSessions)
{
OnPeekAtResponseHeaders(session); //Run whatever function you use in IAutoTamper
session.RefreshUI();
}
FiddlerApplication.UI.lvSessions.EndUpdate();
}
I hope that helps someone else.
Hello guys I'm new to the forum also programming and need some help about a project.
So I recently start developing a program that firstly must add its path at the end of Registry => Environment => Path.
For this job I created project (MainLogic) which contain a class (Program) that do the job, Installer Class that contains this events below and configured Setup Project. SOURCE
public InstallerClass1()
{
this.Committed += InstallerClass1_Committed;
this.Committing += InstallerClass1_Committing;
}
private void InstallerClass1_Committing(object sender, InstallEventArgs e)
{
//Console.WriteLine("");
//Console.WriteLine("Committing Event occurred.");
//Console.WriteLine("");
}
private void InstallerClass1_Committed(object sender, InstallEventArgs e)
{
Directory.SetCurrentDirectory(Path.GetDirectoryName
(Assembly.GetExecutingAssembly().Location));
Process.Start(Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location) + "\\MainLogic.exe");
}
The program was installed correctly but MainLogic.exe file I call after installation cause an error and can't start. The exception is Null Reference at MainLogic.Program.Main(String[] args)
Here is a picture for better understanding -
Is there a way to avoid that exception or could you offer me another that will work.
*** Here what i found. I can execute creating and typing in to file. Writing on the console. Probably a lot of other stuff without problem. But when try to execute this peace of code which actually I have to use...
Registry.CurrentUser.OpenSubKey("Pass Key", RegistryKeyPermissionCheck.ReadWriteSubTree).SetValue("Finaly", "Done");
Registry.CurrentUser.Close();
...the exception I described above occurs. Suggestions?
So the main reason for all those "exercises" is because I want to implement ffmpeg in my application.
I guess you are hear about ffmpeg (a video/audio processing program that works in command prompt).
So what I'm working on is to implement it in my project for mp3 extracting from video files but I wanna make it more user friendly so the user can pass commands through GUI and from there my code should do the other job. So ffmpeg works through command prompt (I know there is a wrappers but I'm not very satisfied with what read about) but firstly you have to add his path to Path's value in the registry. And here's where my problem came from.
Maybe it's sounds stupid for you but you know.. when you start something make it all the way.
If course you can just add exception handling and see what goes wrong but you don`t neet that anyway. Try to set the registry key directly in your Installer
[RunInstaller(true)]
public partial class Installer1 : Installer
{
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
const string key_path = "SOFTWARE\\YourCompany\\YourApplication";
const string key_value_name = "InstallationDirectory";
RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree);
if (key == null)
{
key = Registry.LocalMachine.CreateSubKey(key_path);
}
string tgt_dir = "someDirectory";
key.SetValue(key_value_name, tgt_dir);
}
if you want to alter the path enironment variables set the key there. You can simply add a new variable or look for an exiting one (including the value) for example with Registry.GetValue MSDN-Link
User Variables
HKEY_CURRENT_USER\Environment
System Variables
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
I need to add 2 type of links to existing report with c#. For exapmle:
1) http://www.google.co.il/
2) file:///C:/index.html
I added the links, but only the "http://" works. when I press the link of "file:///" nothing happens.
I've uploaded the full project (very small though) which includes the problem:
http://www.filefactory.com/file/452gsoyymalv/n/ObjectReports.zip
BTW, the "index.html" is a simple 'helloWorld' which loaded successfully when writing the path on the address bar in the browser.
Do anyone knows what additional settings should be set to make the file link work?
*Credit for the sample (without my case):
http://www.c-sharpcorner.com/uploadfile/mahesh/reportviewerobject04172007111636am/reportviewerobject.aspx
AFAIK this is disabled for security reasons - the ReportViewer is NOT a complete browser...
You can try to circumvent that limitation by handling ReportViewer.Hyperlink event yourself... can't try it myself right now, but that's about the only option that can possibly work IMHO...
This is the detailed solution (main idea suggested by #Yahia):
First, I created the event handler:
public void HyperLinkReportHandler(Object sender, HyperlinkEventArgs e)
{
Process.Start(e.Hyperlink);
}
Second, I associated the event handler:
this.rvContainer.Hyperlink += HyperLinkReportHandler;