Question - Should I use SPItemReceiver or SPEmailEventReceiver - visual-studio-2010

I have custom SharePoint Document Library which I use to upload spreadsheet data into a database. When a spreadsheet is uploaded, the SPItemReceiver triggers, and upload the data.
Now, I would like to add an incoming email feature to the document library.
My question is...after the document library has received the spreadsheet by email. Should I use the override-able method EmailReceived of the SPEmailEventReceiver to process the data in the spreadsheet or still use the SPItemReceiver?
I gather I could use either, but I would like to know your opinion which is better and why.
Thanks in advance

You should use SPEmailEventReceiver to process the data. This will make it easy for you to maintain your code and debug. Below is the sample code to process the data. In this code itself, you can include the code to upload the data into database.
public class EmailHandler: SPEmailEventReceiver
{
public override void EmailReceived(
SPList objList,
SPEmailMessage objMessage,
string strReceiverData)
{
SPListItem objListItem = objList.Items.Add();
objListItem["Title"] = objMessage.Headers["Subject"];
objListItem["Body"] = objMessage.HtmlBody;
objListItem.Update();
}
}

Related

Get ALL Entity Metadata in Dynamics CRM

What I want to do is:
Retrieve all metadata from CRM.
Serialize that metadata and store it in a file.
At a later point, deserialize and eed that metadata to XrmFakeEasy for unit tests.
Steps 2 and 3 are done but I don't know how to accomplish step 1.
I've spent some time noodling around in the code and on Google but remain stumped.
We're using .Net so what I need is to read ALL the Entity Metadata (type: Microsoft.Xrm.Sdk.Metadata.EntityMetadata).
If anyone knows how to do this or can point me in the direction of the API (I haven't been able to find one) then please let me know.
P.S.
This case is for on-premise crm.
If I get it right you need to use RetrieveAllEntitiesRequest request.
Here are more details: https://stackoverflow.com/a/29694213/2575544
For the benefit of anyone that comes across this post here's
My final solution
public static EntityMetadata[] GetMetadata(IOrganizationService crmService)
{
var request = new RetrieveAllEntitiesRequest
{
EntityFilters = EntityFilters.All
};
var response = (RetrieveAllEntitiesResponse) crmService.Execute(request);
return response.EntityMetadata;
}

Getting the content from a MailMessage object

I am trying to create a system that will automatically log the content of any email notifications that my site sends to users, against their accounts.
I am doing this by listening for the NotificationSent event, which provides me with easy access to the Notifiable (the object that I want to store my log entry against) and the Notification (the object that defined the message that has been sent).
Using these I am able to get hold of the MailMessage object, but I can't work out how to render it. I was hoping it would have a render method but I can't find one. Presumably there is some other object that takes the MailMessage and does the rendering. Any clues?
Ideally I'd like the plain text version of the email (the markdown)
Thanks for any help
I've got a solution that is doing what I want. I cannibalised some code I wrote for something else, that got me a long way there. There are some steps that I don't completely understand so there may well be some unnecessary bloat in here:
class LogNotification
{
public function handle(NotificationSent $event)
{
//getting the MailMessage object
$mailMsg = $event->notification->toMail($event->notifiable);
//I think this is getting the additional variables from the
//MailMessage that are needed to render the view
$msgData = array_merge($mailMsg->toArray(),$mailMsg->viewData);
//I don't fully understand this. I get that the Markdown object is
//going to do the rendering, but I don't know why it needs to be
//instantiated with an empty View object
$markdown = new \Illuminate\Mail\Markdown(view(), config('mail.markdown'));
//Pass the renderText method the path to the markdown, and the message data
$msgContent = $markdown->renderText($mailMsg->markdown, $msgData);
}
}
Hopefully this is helpful to someone (and if anyone can offer a proper explanation of what is happening when the Markdown object is instantiated, I'd be grateful).

how to save and load a object in a windows phone 7 app?

is it possible in a WP7 app to save some objects which i create and then load it when the app is started again?
You'll want to look to store persistent items into IsolatedStorage. You can see an overview and an example of how to use IsolatedStorage here. There are also a range of examples on this site, showing how to save different types of objects.
Here's an example storing a string, but you should be able to store any type of object this way.
Add IsolatedStorage to your references:
using System.IO.IsolatedStorage;
In your class:
private string myString;
In the Loaded event for your page:
try
{
myString = (string)IsolatedStorageSettings.ApplicationSettings["myString"];
}
catch
{
IsolatedStorageSettings.ApplicationSettings.Add("myString", "this value is a string");
}
and later, when you want to save:
IsolatedStorageSettings.ApplicationSettings["myString"] = myString;
try after
the example code above to add this.
IsolatedStorageSettings.ApplicationSettings.save

how to manage the data in an xml file in wp7?

I have written a simple wp7 application. i am using wcf service to interact with the database. Now i want to store a part of user's info in the mobile also. this info needs to be accessible across the wp7 app.
I found multiple ways to do this like : isolated storage, resource files or static data in the app.xaml
Which one would be more suitable? as i may wish to edit the data in future...i may not opt for packaged files as they are read-only. also do not wish to lose data by storing in isolated storage.
Please suggest the most suitable option for me
Thanks in advance
Bindu
It sounds like you want to store downloaded data between uses of the app. In this case Isolated Storage is probably your best bet. It will remain in the phone's non-volatile memory and you will not lose it.
Details here
Resource files and static data in the app.xaml won't work for you since you want to be able to change these items at a later date since these will be read only.
I don't know what you are referring to when you say "lose data" by storing in IsolatedStorage. This is your best bet and is actually really easy to do. Here is an example of saving a simple boolean:
private void SaveSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["VibrationOn"] = VibrationOn;
}
Then to load it later:
private void LoadSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
bool vo;
if (settings.TryGetValue<bool>("VibrationOn", out vo))
VibrationOn = vo;
else
VibrationOn = true;
}
You would call your LoadSettings() method in the Application_Launching and Application_Activated events and then your SaveSettings() in the Application_Deactivated and Application_Closing events within your App.xaml.cs.
You can also serialize objects or write whole files.

Ajax / Json How to run an INSERT/UPDATE into mysql

Again related with my weekend project, I'm trying to learn a bit more of web-development. So I'm putting in the list of features i want to implement, some stuff i absolutely have no idea how to do.
I've been reading tutorials on how to use ajax, but i can't find a simple one, that i can copy-paste (with one or two changes) to see it work before i go into the how it works.
What I've been searching is just a simple example on an ajax function, that triggers a mysql insert or update. Anyone as a simple example on how to do this? I think it would prove a nice start to learn it. (Ajax or Json are both ok).
Correct me if I'm mystaken: I'm basing myself on this tutorial. So as obviously the client side doesn't have access to database calls, what I should do, would be something like creating a code snippet to add stuff to the database right? For example create an "addcomment.php" that can be called with xhr.open(GET, "addcomment.php?comment=mycomment", true);
Sounds like you got it right. Use Ajax to call a server side script which then does the database work for you.
A good setup is to use a framework like jQuery on the client side. This framework will encode and decode JSON automatically. On the server side you could create a class that handles all the ajax (or rather, ajaj, since we are using JSON) requests. Here is a short PHP file that shows the general idea. Add more elements to the functionMap array, and add the respective functions to the class.
class Ajaj{
private $callback = "";
private $functionMap = array( "select" => 'getIt');
function Ajaj(){
if(array_key_exists('jsoncallback',$_GET)){
$this->callback=$_GET['jsoncallback'];
}
}
function parse(){
echo "$this->callback(";
if(array_key_exists('action', $_POST)){
$action = $_POST['action'];
if(array_key_exists($action, $this->functionMap)){
echo $this->functionMap[$action];
}
}else{
echo "{}";
}
echo ")";
}
function getIt(){
return json_encode(//get the database stuff here);
}
}
$ajaj = new Ajaj();
$ajaj->parse();

Resources