I am creating a VSTO 2007 Addin using COM. My requirement is to mark all the new mails into Blue category. I have the following code in OnNewMailEx handler
HRESULT hrGetNewMail;
_NameSpacePtr pMAPI = NULL;
hrGetNewMail = spApp->GetNamespace((_bstr_t)GetStringFromTable(147),&pMAPI);
if(FAILED(hrGetNewMail))
{
if(spApp!=NULL)
spApp.Release ();
return OPERATION_FAILED;
}
if(spApp!=NULL)
spApp.Release ();
CComBSTR EntryStoreID;
MAPIFolderPtr spMAPIFolder = NULL;
hrGetNewMail = pMAPI->GetDefaultFolder (olFolderInbox, &spMAPIFolder);
if(FAILED(hrGetNewMail))
{
if(pMAPI!=NULL)
pMAPI.Release ();
return OPERATION_FAILED;
}
hrGetNewMail = spMAPIFolder->get_StoreID (&EntryStoreID);
if(FAILED(hrGetNewMail))
{
if(spMAPIFolder!=NULL)
spMAPIFolder.Release ();
if(pMAPI!=NULL)
pMAPI.Release ();
}
if(spMAPIFolder!=NULL)
spMAPIFolder.Release ();
VARIANT varEntryStoreID;
hrGetNewMail = EntryStoreID.CopyTo (&varEntryStoreID);
if(FAILED(hrGetNewMail))
{
return OPERATION_FAILED;
}
IDispatch* spLatestMailitem;
hrGetNewMail = pMAPI->GetItemFromID (EntryID,varEntryStoreID,&spLatestMailitem);
if(FAILED(hrGetNewMail))
{
if(pMAPI!=NULL)
pMAPI.Release ();
}
if(pMAPI!=NULL)
pMAPI.Release ();
CComQIPtr <Outlook::_MailItem> spMailItem;
hrGetNewMail=spLatestMailitem->QueryInterface(&spMailItem);
HRESULT hrCat = spMailItem->put_Categories(_T("Blue Category"));
//spMailItem->put_FlagIcon(olRedFlagIcon);
hrCat = spMailItem->Save();
after execution when i open the new mails it is showing the category as Blue but in the inbox it is not marked in any category. When i close and open the outlook the category is gone even when i open the mail which was earlier marked as blue category. however i could add a flag which is there whenever i close and open the outlook. please suggest me the problem
If the category does not exist in the master category list I don't think it keeps it. To add a category to the master category list. See for more information http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.categories.aspx
Also you example will overwrite any existing categories. you should check if a category is already specified and if so seperate the existing value and value you wish to add with a comma.
var existingCategories = item.Categories;
if (string.IsNullOrWhiteSpace(existingCategories))
{
item.Categories = "MyCategory";
}
else
{
if (item.Categories.Contains("MyCategory") == false)
{
item.Categories = existingCategories + ", MyCategory";
}
}
item.Save();
Related
I'm working on a script that should go through a photoshop document and relink all visible linked objects to a new specified file. I've gotten the loop working so that it cycles through every layer and collects only the visible layers, but for the life of me I can't find if there's a method available to relink a smart object. The closest I've found is this script:
https://gist.github.com/laryn/0a1f6bf0dab5b713395a835f9bfa805c
but when it gets to desc3.putPath(idnull, new File(newFile));, it spits out an error indicating that the functionality may not be present in the current Photoshop version. The script itself is 4 years old so it may be out of date.
Any help would be appreciated!
MY script as it stands is below:
// SELECT FILE //
var files = File.openDialog("Please select new linked file");
var selectedFile = files[0];
// GET ALL LAYERS //
var doc = app.activeDocument;
var allLayers = [];
var allLayers = collectAllLayers(doc, allLayers);
function collectAllLayers (doc, allLayers)
{
for (var m = 0; m < doc.layers.length; m++)
{
var theLayer = doc.layers[m];
if (theLayer.typename === "ArtLayer")
{
allLayers.push(theLayer);
}
else
{
collectAllLayers(theLayer, allLayers);
}
}
return allLayers;
}
// GET VISIBLE LAYERS //
var visibleLayers = [];
for (i = 0; i < allLayers.length; i++)
{
var layer = allLayers[i];
if (layer.visible && layer.kind == LayerKind.SMARTOBJECT)
{
visibleLayers.push(layer);
}
}
// REPLACE LAYERS
for (i = 0; i < visibleLayers.length; i++)
{
var layer = visibleLayers[i];
//--> REPLACE THE FILE HERE
}
Note: I am aware that this script currently may be error-prone if you don't know exactly how it works; I'm not intending to publish it at this time so I'm not super concerned with that at the moment. Mostly I just need the core functionality to work.
I used an AM function for getting visible smart objects — it works much faster. But if you want you can use yours. The important bit is relinkSO(path);: it'll also work in your script (just don't forget to select a layer: activeDocument.activeLayer = visibleLayers[i];)
Note that it works similar to Photoshop Relink to File command — if used on one instance of Smart Object all the instances are going to be relinked. If you want to relink only specific layers you'll have to break instancing first (probably using the New Smart Object via Copy command)
function main() {
var myFile = Folder.myDocuments.openDlg('Load file', undefined, false);
if (myFile == null) return false;
// gets IDs of all smart objects
var lyrs = getLyrs();
for (var i = 0; i < lyrs.length; i++) {
// for each SO id...
// select it
selectById(lyrs[i]);
// relink SO to file
relinkSO(myFile);
// embed linked if you want
embedLinked()
}
function getLyrs() {
var ids = [];
var layers, desc, vis, type, id;
try
{
activeDocument.backgroundLayer;
layers = 0;
}
catch (e)
{
layers = 1;
}
while (true)
{
ref = new ActionReference();
ref.putIndex(charIDToTypeID('Lyr '), layers);
try
{
desc = executeActionGet(ref);
}
catch (err)
{
break;
}
vis = desc.getBoolean(charIDToTypeID("Vsbl"));
type = desc.getInteger(stringIDToTypeID("layerKind"));
id = desc.getInteger(stringIDToTypeID("layerID"));
if (type == 5 && vis) ids.push(id);
layers++;
}
return ids;
} // end of getLyrs()
function selectById(id) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), id);
desc.putReference(charIDToTypeID('null'), ref);
executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
} // end of selectById()
function relinkSO(path) {
var desc = new ActionDescriptor();
desc.putPath( charIDToTypeID('null'), new File( path ) );
executeAction( stringIDToTypeID('placedLayerRelinkToFile'), desc, DialogModes.NO );
} // end of relinkSO()
function embedLinked() {
executeAction( stringIDToTypeID('placedLayerConvertToEmbedded'), undefined, DialogModes.NO );
} // end of embedLinked()
}
app.activeDocument.suspendHistory("relink SOs", "main()");
I have the code below, but i've been struggling to get it to work properly, either it creates duplicate folders every time i run it, or it doesn't upload the attachments and just creates the folders... I am also getting an error now that the newMail Uploads object does not have a .hasnext() function.
What i want to do, is have this script running and it puts attachments in a folder relating to their label -- So in the code below, all mail with the newMail label would go to a single folder, but i want to be able to extend the code further to run for multiple labels ect, so i want to check if the relevant folders exist and if not create them, if they exist they should be used.
-Edit, Now it is only taking the attachment from the first email from a certain address.
function startProcess()
{
var gmailLabels = "newLabel";
var driveFolder = "newFolder";
var archiveLabel = "Processed";
var moveToLabel = GmailApp.getUserLabelByName(archiveLabel);
if ( ! moveToLabel )
{
moveToLabel = GmailApp.createLabel(archiveLabel);
}
findFolder(gmailLabels, driveFolder, archiveLabel, moveToLabel);
}
function findFolder(gmailLabels, driveFolder, archiveLabel, moveToLabel)
{
var filter = "has:attachment label:" + gmailLabels;
var folder = DriveApp.getFoldersByName(driveFolder);
if (folder.hasNext()) {
folder = folder.next();
} else {
folder = DriveApp.createFolder(driveFolder);
}
callThreads(gmailLabels, driveFolder, archiveLabel, moveToLabel, filter, folder)
}
function callThreads(gmailLabels, driveFolder, archiveLabel, moveToLabel, filter, folder)
{
var threads = GmailApp.search(filter);
for (var x=0; x<threads.length; x++) {
var label = GmailApp.getUserLabelByName(gmailLabels);
var message = threads[x].getMessages()[x];
var desc = message.getSubject() + " #" + message.getId();
var att = message.getAttachments();
for (var z=0; z<att.length; z++) {
try {
file = folder.createFile(att[z]);
file.setDescription(desc);
}
catch (e) {
Logger.log(e.toString());
}
}
//threads[x].addLabel(moveToLabel);
label.removeFromThreads(threads);
//threads[x].moveToTrash();
}
}
This is just a suggestion. I haven't tested this code, it probably doesn't work. But that's not the point. I'm trying to show how you might create some order to your code so that it's easier to understand and debug:
function sendToGoogleDrive() {
makeNewFolders();
putEmailsIntoFolders();
};
function makeNewFolders() {
var gmailLabels = "newMail";
var driveFolder = "newMail";
var archiveLabel = "Processed";
var rootUploadFolders ="newMail Uploads";
var rootDriveFolder = DriveApp.getFolders();
var rootExist = false;
var childExist = false;
while (rootDriveFolder.hasNext()) {
var folder = rootDriveFolder.next();
if(folder.getName()==rootUploadFolders) {
var folderId = folder.getId();
if(folder.getName()!==driveFolder) {
var child = DriveApp.getFolderById(folderId).createFolder(driveFolder);
};
};
};
};
function putEmailsIntoFolders() {
};
I'm Developing windows phone 8 application.
In my application i'm using listbox.I bind listbox value form Webservice. Webservice return json format data's.
The webservice return 40 to 50 records.I bind all the values into listbox.
Everthing work fine.Only on first time run.
For example:-
My project page structure.
1.welcomepage
2.Menu Page (it contain six buttons. click on any one particular button it's redirect to sub-menupage)
3.Sub-menupage(Six different page present)
In menu page Hotels button is present . if hotels button is clicked it's navigate to Hotels Page.
Now my problem is:-
First Time - welcomepage -> Menu Page -> HotelSubmenu [List of hotels is bind in listbox from webservice]
Now I goback to Menupage by click on hardwareback button.Now it's in Menu page
If i click again the same Hotels button
It show me the error
e.ExceptionObject {system.OutofMemoryException:Insufficient memory to continue the execution of the program.
[System.outofmemoryException]
Data {system.Collections.ListDictionaryInternal}
HelpLink null
Hresult -2147024882
Message "insufficient memory to continue the execution of the program"
My C# code for bind values in listbox
public void commonbind()
{
try
{
this.loadimg.Visibility = System.Windows.Visibility.Visible;
loadcheck();
string common_url = "http://xxxxxx.com/Service/bussinesscitynamesub.php?bcatid=" + businessid + "&cityname=" + cityname + "&bsubid=" + filterid;
WebClient common_wc = new WebClient();
common_wc.DownloadStringAsync(new Uri(common_url), UriKind.Relative);
common_wc.DownloadStringCompleted += common_wc_DownloadStringCompleted;
}
catch (Exception ex)
{
}
}
void common_wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
lbbusiness.Items.Clear();
var common_val = e.Result;
if (common_val != "null\n\n\n\n")
{
lbopen = 2;
var jsonconvertvalue = JsonConvert.DeserializeObject<List<common_bindclass>>(common_val);
List<common_bindclass> ls = new List<common_bindclass>();
ls = jsonconvertvalue;
for (int i = 0; i < ls.Count; i++)
{
lbbusiness.Items.Add(ls[i]);
}
this.loadimg.Visibility = System.Windows.Visibility.Collapsed;
loadcheck();
}
else
{
if (lbopen == 0)
{
MessageBoxResult resultmsg = MessageBox.Show("No Result present based on your current Location! " + System.Environment.NewLine + "Now showing result without Location based", "Sorry!", MessageBoxButton.OK);
if (resultmsg == MessageBoxResult.OK)
{
lbbusiness.Items.Clear();
cityname = "";
**commonbind();**
}
else
{
NavigationService.GoBack();
}
}
else if (lbopen == 1)
{
MessageBox.Show("No Result Present In this Categories");
LPfilter.Open();
}
else if (lbopen == 2)
{
MessageBox.Show("No Result Present In this City");
Lpcity.Open();
}
}
}
catch (Exception ex)
{
}
}
I try with following method for solve the memory exception
Try1:-
Clear the List box value before bind every time.
Try2:-
Create the new list every time
common_bindclass bind = new common_bindclass();
foreach (common_bindclass bind in jsonconvertvalue)
{
lbbusiness.Items.Add(bind);
}
I change the above code to
List<common_bindclass> ls = new List<common_bindclass>();
ls = jsonconvertvalue;
for (int i = 0; i < ls.Count; i++)
{
lbbusiness.Items.Add(ls[i]);
}
MY Output For single List
But my try's not help for me .
any one tell me how to solve it. or alternate way .
How to find in which line the error occur .[I try with break point but it's not help me]
I am creating VSTO 2007 outlook Addin using COM . It reads all the mailtems from outlook and marks(categories) the undelivered mail items as undelivered.
I am using below code for marking the undelivered mail item as undelivered. The code marked in read colour crashes sometimes. Please suggest me the problem.
HRESULT hrGetSelectedItem;
LPDISPATCH spOlSelectedItem = NULL;
CComPtr<Outlook::_Explorer> spExplorer;
//Locating the selected item
CComPtr<Outlook::Selection> spOlSel;
if(m_spApp)
{
//Get the Currently Active Explorer on the top of Desktop
hrGetSelectedItem = m_spApp->ActiveExplorer(&spExplorer);
if(SUCCEEDED(hrGetSelectedItem))
{
hrGetSelectedItem = spExplorer->get_Selection(&spOlSel);
if(FAILED(hrGetSelectedItem))
{
MessageBox(NULL,GetStringFromTable(IDS_SELECTITEM),MSGBOX_HEADER, MB_OK|MB_ICONINFORMATION);
return ;
}
iMailIndex+=1;
VARIANT covIndex;
covIndex.vt = VT_I4;
covIndex.lVal = iMailIndex;
if(spOlSel)
{
hrGetSelectedItem = spOlSel->Item(covIndex,&spOlSelectedItem);
CComQIPtr <Outlook::_MailItem> spMailItem;
if(spOlSelectedItem)
{
hrGetSelectedItem = spOlSelectedItem->QueryInterface(&spMailItem);//Get The selected item
if(spMailItem)
{
spMailItem->put_Categories(L"Undelivered");
spMailItem->Save();
}
}
}
}
} LPDISPATCH spOlSelectedItem = NULL;
CComPtr<Outlook::_Explorer> spExplorer;
//Locating the selected item
CComPtr<Outlook::Selection> spOlSel;
if(m_spApp)
{
//Get the Currently Active Explorer on the top of Desktop
hrGetSelectedItem = m_spApp->ActiveExplorer(&spExplorer);
if(SUCCEEDED(hrGetSelectedItem))
{
hrGetSelectedItem = spExplorer->get_Selection(&spOlSel);
if(FAILED(hrGetSelectedItem))
{
MessageBox(NULL,GetStringFromTable(IDS_SELECTITEM),MSGBOX_HEADER, MB_OK|MB_ICONINFORMATION);
return ;
}
iMailIndex+=1;
VARIANT covIndex;
covIndex.vt = VT_I4;
covIndex.lVal = iMailIndex;
if(spOlSel)
{
hrGetSelectedItem = spOlSel->Item(covIndex,&spOlSelectedItem);
CComQIPtr <Outlook::_MailItem> spMailItem;
if(spOlSelectedItem)
{
hrGetSelectedItem = spOlSelectedItem->QueryInterface(&spMailItem);//Get The selected item
if(spMailItem)
{
spMailItem->put_Categories(L"Undelivered");
spMailItem->Save();
}
}
}
}
}
Thanks in advance.
You need to check that spExplorer is not null. Outlook can be open with no Explorers.
ive made a small app using c# for sp 2010, what i am doing is getting items from a collection and viewing specific fields that i want to, the problem is when i click an item it shows me the details of every item assigned to the current user, how can i show only the details of the current item which the user clicks, below is my code...thanks
foreach (SPListItem myItem in myItemCollection)
{
if (myList.Fields.ContainsField("Title"))
{
EntreeListItemDetailNameValue l = lGrp.AddListItem<EntreeListItemDetailNameValue>();
SPField myField1 = myList.Fields.GetField("Title");
l.Name = myField1.Title;
try
{
l.Value = myField1.GetFieldValueAsText(myItem["Title"]);
}
catch
{
l.Value = "";
}
}
if (myList.Fields.ContainsField("Priority"))
{
EntreeListItemDetailNameValue l2 = lGrp.AddListItem<EntreeListItemDetailNameValue>();
SPField myField = myList.Fields.GetField("Priority");
l2.Name = myField.Title;
try
{
l2.Value = myField.GetFieldValueAsText(myItem["Priority"]);
}
catch
{
l2.Value = "";
}
You could use GetItemById()
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitemcollection.getitembyid.aspx
void list_Click(object sender, EventArgs e) {
int clickedid = 0; //get the id from the clicked item
ShowForm(); //show detail form
DataBind(clickedid); //databind detail form
}
void DataBind(int id) {
SPListItemCollection myItemCollection = showthing; //load the list items, query using SPQuery, or SPList.Items
SPListItem item = myItemCollection.GetItemById(id);
form.Title = item["Title"];
}