When I remove a user control property that I have created and used in a project. There will be as many errors as times I have used control in project. For example imagine I have user control and it has a property named p1. when I remove p1 I get errors saying myusercontrol.p1 doesn't exist.
Is there a way to get rid of them automatically?
If you want to remove a property, go ahead and do so - and fix all errors you find after that.
You could use ReSharper's Safe Delete, but that'll do little if you actually used the property:
var foo = someClass.PropertyToRemove;
bar.CallMethod(someClass.PropertyToRemove);
The code was there for a reason, and ReSharper cannot figure out for you what that code should become if you remove someClass.PropertyToRemove.
Related
I have tried finding an answer to this question practically everywhere I could imagine, including here on StackOverflow. Unfortunately to no avail. So here it is.
I'm working on an Outlook Add-in (with Outlook 2021), and have developed some code that creates some ItemProperties specifically for use with that add-in. Now, when those properties are created, I can see them when I go to View->Settings->Advanced View Settings->Columns, as illustrated in the screenshot.
Screenshot of User-defined fields in Outlook
In some cases, though, I want to completely delete the properties. And as I know how to do that manually, as pointed out in the figure, I can't find out how to do that programmatically via C#. I have gone that far as to remove the properties from each mail containing that kind of property, like this:
IEnumerable<MailItem> listOfAssignedEmails = itemsToProcess.Where(
t => t.ItemProperties[MailExpiration.ExpirationDatePropertyName] != null);
foreach (MailItem email in listOfAssignedEmails)
{
// Note: The Delete() operation is deprecated. A more up-to-date method must be found.
email.ItemProperties[MailExpiration.ExpirationDatePropertyName].Delete();
email.Save();
}
... and yes, I know that the Delete() operation is deprecated; however, I couldn't find another method for removing the ItemProperty from the email (any suggestions are welcome).
Basically, the deletion of this Property is only going to be done very rarely (t. ex. if the user chooses to uninstall the Add-in. However, if there's any way to remove that property automatically, I would be happy to know.
Any suggestions will be greatly appreciated.
It is really a bad idea to remove a custom property from all emails that already have it: there is really no point since the user will never see them, but you will have to retouch (and thus change the last modified date) of a large number of emails.
Also note that named properties in MAPI are a finite resource - you can have at most 64k of them in a mailbox. Once a particular property mapping is used, you can never unmap it, even if there are no items that use that property.
Thirdly, doing anything Outlook related from an installer (rather than a VSTO addin) is a really bad idea - Windows installer runs in a service.
If you want to make sure the user no longer sees your custom fields as available properties in a view, you need to deal with the folder fields - they ar stored in a blob in a hidden (associated) message in that folder. OOM does not expose folder fields at all (if you don't count the AddToFolderFields parameter when calling UserProperties.Add). If using Redemption is an option (I am its author), it exposed RDOFolderFields object (accessible from RDOFolder2.FolderFields property) that allows to add or delete folder fields.
The list of properties shown on the screenshot belongs to the Folder.UserDefinedProperties property which returns a UserDefinedProperties object that represents the user-defined custom properties for the Folder object.
Use the ItemProperties.Remove method removes an object from the collection (from an item).
Use the ItemProperties property to return the ItemProperties collection. Use ItemProperties.Item(index), where index is the name of the object or the numeric position of the item within the collection, to return a single ItemProperty object.
I just realized if I don't put my asp.net controls inside a form with runtat="server" attribute I will get a error like this:
Control 'ctl25' of type 'Button' must be placed inside a form tag with
runat=server
Although its really easy to debugging this error I'm just curious is it possible to understand which object is ctl25? Because I searched carefully all object attributes, .aspx, .aspx.cs and .aspx.designer.cs files but I couldn't find anything with ctl25 label.
So is it possible to find ctl25 referring to which object?
Actually, setting ID is somewhat optional (server-side-access can be achieved by iterating over Controls-property of parent, and client-side-access just needs ClientID, which is done automatically), by leveraging on the automatic ClientID-setting.
So there's a fairly good chance that you'll never see ID="ctl25" as it might be/is done automagically.
Just give the control in question an explicit ID, and you should be fine.
I'm trying to do something my teacher says can't be done; I would like to prove him wrong.
In the CreateChildControls method of my SharePoint 2010 webpart, I am referencing a User Control file called "ChartUserControl.ascx" in my project that contains the ASP.NET code for a WebChartControl object configured just the way I want it. WebChartControl has an ID of "OrderQtyChart".
What I want to do is take the code from that UserControl and use it create a new WebChartControl, called "chart", with matching configuration. I'm trying to do this because there are callbacks etc. that need to be performed on the chart after it's created to actually populate it with chart-stuff.
So, my code:
WebChartControl chart;
protected override void CreateChildControls()
{
ChartUserControl userControl = new ChartUserControl();
// referencing file ChartUserControl.ascx as an object
chart = userControl.FindControl("OrderQtyChart") as WebChartControl;
// or
chart = (WebChartControl)userControl.FindControl("OrderQtyChart");
// Trying to tell the code to create 'chart' using the code defined in object
"OrderQtyChart" located in ChartUserControl.ascx
}
Or something like that. In either instance above, 'chart' will return null.
I'm trying to use the front end code of OrderQtyChart as a template for 'chart'; they're both the same type of object and I don't get any errors until I try to create 'chart' on my page, at which point I'm told it's null.
Is there a way to do this? It would save me a ton of time not to have to configure 'chart' completely at creation time. Even if I have to reference my front-end code for OrderQtyChart a different way.
Thanks.
[Edited 7/9 for clarity]
What you are trying to do seems very well possible and I assume your teacher did not understand your question correctly. Here are a few tips on how this is done:
Object A could be one of these:
A visual control such as label or textbox. In this case your will have to traverse the visual controls from parent to child by doing direct parent.FindControl("ObjectA");
It is an instance of a class. This might be a MyClass or a new textbox that is created by code. In this case you'll have to create a public property that has a getter which returns ObjectA. although you can use FindControl in case ObjectA is a UI component that is created and added dynamically at run-time. Otherwise, you'll have to stick with property.
FindControl will not traverse the parent to child hierarchy, so you'll have to do a recursive method in order to successfully find the ObjectA or if you have access to its direct parent, call FindControl on that. More info here: http://geekswithblogs.net/QuandaryPhase/archive/2009/05/06/asp.net-recursive-findcontrol-amp-extension-methods.aspx
Page life cycle plays an important role here, so make sure that you keep it in mind or you'll end up with a null reference that is not really caused by FindControl
Gah, never mind. I realized I can just call the user control directly and I'm seriously overcomplicating this.
That's a whole new question, so I'll just start a different thread.
I have a control which is a TreeView node that will always be set to the name of the PC you're currently running the tested software on. Therefore I need the Search Property for the control's Name property to be set to `Environment.MachineName like so:
The problem with this is that inside UIMap.Designer.cs I can see the generated code that this makes and it's trying to use Environment.MachineName as a string:
this.SearchProperties[WinTreeItem.PropertyNames.Name] = "Environment.MachineName";
Obviously this approach won't work, and it's not possible to manually edit UIMap.Designer.cs to change this. How can I make this work then?
The general approach is to use the UI Map editor to remove that search item. This should be possible from the window shown in the question. Then, in the test method that needs to do the search, add a statement something like
this.uimap.controlNames.SearchProperties[WinTreeItem.PropertyNames.Name]
= Environment.MachineName;
or
this.uimap.controlNames.SearchProperties.Add(name, Environment.MachineName;
The precise statement depends on the structure of the controls, so where I wrote .controlNames. it may need a series of dot-separated control names.
To make this clear, I'm using .net 3.5
I'm currently creating an Visual Studio Visualizer in order to be able to see the values of individual rules in a WF RuleSet. Everything is ok, but now I need to do the following.
Let's say I have a rule which is "this.Age > 50" and one then action as MessageBox.Show("Bigger than 50") and one else action as MessageBox.Show("Less than 50")
I need to be able to select the rule "this.Age > 50" and evaluate it as true or false. Or I need to select part of the rule, eg. "this.Age" and evaluate it to let's say 70.
This last bit is working. I'm getting the object in which the RuleSet executes and getting the fileds and try to find one field named Age and if I do find, I get it's value, on the event of not finding the field I then look at properties. This is working.
The problem is evaluating "this.Age > 50". Of course, I could do a parser in this case and evaluate it, but the problem is then I would have to evaluate "this.Age > 50", "this.Age < 50"... I guess you understand the problem. And of course I also want to evaluate for example, "this.GetCurrentAge()", in which GetCurrentAge() is a method in the class represented by the object in which context the RuleSet executes.
I've thought I could try to inject a method at runtime into the object I currently have and which is instantiated. This way, I could create something as simples as
public string EvaluationMethod()
{
return (this.Age > 50).ToString();
}
in this case, I would at runtime build this method and inject it in the current instance of object.
The problem is that I can't seem to find a way to inject code into the current instance of the object. I can only find examples on how to create new classes at runtime, but nothing about only creating a method and inject it.
Can someone please help, or give any other idea?
Thanks