Image showing in attachment instead of mail body - asp.net-mvc

I have problem with an embedded image in email. When receiving mail I show image in attachment instead of message body and I have add image dynamically in message body. And also I have set "cid" but I have not success. I have set ishtmlbody = true but not showing image in body. please solve my problem.
My code is here:
This is my body message:
const string to = "test#gmail.com";
msg.To.Add(to);
msg.From = new MailAddress("test#gmail.com");
msg.Subject = "test";
int count = 1;
int stratindex = 0;
//Create altenative view
AlternateView alternative = AlternateView.CreateAlternateViewFromString(strMailContent, null, MediaTypeNames.Text.Html);
while ((lastIndex = strMailContent.IndexOf(findStr, stratindex, StringComparison.Ordinal)) != -1)
{
int srcStartIndex =Convert.ToInt32(strMailContent.IndexOf("src", lastIndex, StringComparison.Ordinal)) + 5;
int srcEndIndex = strMailContent.IndexOf(#"'", srcStartIndex, StringComparison.Ordinal);
string imgSrc = strMailContent.Substring(srcStartIndex, srcEndIndex - srcStartIndex);
string path = imgSrc;
// Atteched resource
// set cid
var resource = new LinkedResource(path, "image/jpg");
string cid = "companylogo" + count;
//now add the AlternateView
resource.ContentId = cid;
alternative.LinkedResources.Add(resource);
msg.AlternateViews.Add(alternative);
//now append it to the body of the mail
strMailContent = strMailContent.Replace(strMailContent.Substring(srcStartIndex, srcEndIndex - srcStartIndex), "cid:" + cid);
stratindex = strMailContent.IndexOf("<br/>", lastIndex, StringComparison.Ordinal) + 5;
strMailContent = strMailContent.Remove(stratindex - 5, 5);
stratindex = stratindex - 5;
count++;
}
show in screen short red area show the attachment and yellow area show blank body.
how to solve this problem.

I don't see any problems in your code, you have to ensure the path file is correct

Related

Can you resize images that are passed to UIPrintInteractionController.PrintingItems?

I'm trying to print multiple labels using UIPrintInteractionController.PrintingItems but when the image is loaded it fills the page, is it possible to have multiple images on one page using this method or is there another method that would offer me a better solution? Thanks.
void Print()
{
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Label Printing";
//UIPrintFormatter formatter = new UIPrintFormatter()
//{
// StartPage = 0,
// ContentInsets = new UIEdgeInsets(72, 72, 72, 72),
// MaximumContentWidth = 6 * 72,
//};
int labelAmount = 10;
int x;
NSObject[] labelItems = new NSObject[labelAmount];
for (x = 0; x < labelAmount; x++)
{
labelItems[x] = UIImage.FromFile("Images/BMcAzurri.png");
}
UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
//printer.PrintFormatter = formatter;
printer.PrintingItems = labelItems;
printer.ShowsPageRange = true;
printer.Present(true, (handler, completed, err) => {
if (!completed && err != null)
{
Console.WriteLine("error");
}
});
}
There are a few ways to do what you are asking, here is just one using a graphics context to do your print page rendering.
Load your image into a UIImage instance
You might want to pre-scale/re-scale that image
Create a UIView that is large enough to contain all your rows and columns of that image
Create a UIImageView that contains your image for each row/column on your "printed page" and place it at the correct location in this view
Using an Image render context, convert the UIView that contains your images to a UIImage and queue and print as many of those as you need...
Example:
var printInfo = UIPrintInfo.PrintInfo;
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Label Printing";
var uiImage = UIImage.FromFile("BingWallpaper-2017-05-04.jpg");
var noColumns = 2;
var noRows = 2;
var gapBetweenImages = 25;
int noOfPages = 2;
NSObject[] labelItems = new NSObject[noOfPages];
for (int x = 0; x < noOfPages; x++)
{
var aPrintView = new UIView
{
Frame = new CGRect(0, 0, (uiImage.Size.Width * noColumns) + ((noColumns + 1) * gapBetweenImages), (uiImage.Size.Height) * noRows + ((noRows + 1) * gapBetweenImages))
};
for (int column = 0; column < noColumns; column++)
{
for (int row = 0; row < noRows; row++)
{
var printImage = new UIImageView(uiImage)
{
Frame = new CGRect((column * gapBetweenImages) + (column * uiImage.Size.Width), (row * gapBetweenImages) + (row * uiImage.Size.Height), uiImage.Size.Width, uiImage.Size.Height)
};
aPrintView.Add(printImage);
}
}
UIGraphics.BeginImageContext(aPrintView.Bounds.Size);
aPrintView.Layer.RenderInContext(UIGraphics.GetCurrentContext());
var aPageImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
labelItems[x] = aPageImage;
}
UIPrintInteractionController printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintingItems = labelItems;
printer.ShowsPageRange = true;
printer.Present(true, (handler, completed, err) =>
{
if (!completed && err != null)
{
Console.WriteLine("error");
}
});
Note: !!! This is not handling the clean up, make sure you Dispose of everything after you are done...
Note: This is just a quick example does not handle the aspect ratio of the image to the paper size, you would need to consider that depending upon what you are printing and to what type of printer/paper...
Note: If you were renderering a number of text fields vs. images, you might want to render to a PDF vs a UIImage and print that instead.

Access Nested NSDictionary Items

I have this NSDictionary that i received from an api call:
{
items = (
{
accessInfo = {
accessViewStatus = SAMPLE;
country = US;
embeddable = 1;
epub = {
isAvailable = 0;
};
pdf = {
isAvailable = 0;
};
publicDomain = 0;
quoteSharingAllowed = 0;
textToSpeechPermission = ALLOWED;
viewability = PARTIAL;
webReaderLink = "http://books.google.com/books/reader?id=LdB2_WzYpKgC&hl=&printsec=frontcover&output=reader&source=gbs_api";
};
etag = 1xxAlevFUSc;
id = "LdB2_WzYpKgC";
kind = "books#volume";
saleInfo = {
country = US;
isEbook = 0;
saleability = "NOT_FOR_SALE";
};
searchInfo = {
textSnippet = "The saga of their daily exploits won cartoonist Bill Watterson the coveted Reuben Award for "Outstanding Cartoonist of the Year." Something Under the Bed Is Drooling is a jewel.";
};
selfLink = "https://www.googleapis.com/books/v1/volumes/LdB2_WzYpKgC";
volumeInfo = {
authors = (
"Bill Watterson"
);
averageRating = "4.5";
canonicalVolumeLink = "http://books.google.com/books/about/Something_Under_the_Bed_Is_Drooling.html?hl=&id=LdB2_WzYpKgC";
categories = (
Humor
);
contentVersion = "0.0.1.0.preview.1";
description = "\"Be good to yourself: Buy a copy of this Calvin and Hobbes cartoon book. If you don't laugh out loud at every third strip, check your pulse. You may be dead.\" --Phil Musick, Pittsburgh Press Calvin is a rambunctious six-year-old whose manic antics threaten world peace. Hobbes is his stuffed tiger who comes alive when adults aren\"t around. The saga of their daily exploits won cartoonist Bill Watterson the coveted Reuben Award for \"Outstanding Cartoonist of the Year.\" Something Under the Bed Is Drooling is a jewel.";
imageLinks = {
smallThumbnail = "http://bks8.books.google.com/books?id=LdB2_WzYpKgC&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api";
thumbnail = "http://bks8.books.google.com/books?id=LdB2_WzYpKgC&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api";
};
industryIdentifiers = (
{
identifier = 0836218256;
type = "ISBN_10";
},
{
identifier = 9780836218251;
type = "ISBN_13";
}
);
infoLink = "http://books.google.com/books?id=LdB2_WzYpKgC&dq=isbn:0836218256&hl=&source=gbs_api";
language = en;
pageCount = 127;
previewLink = "http://books.google.com/books?id=LdB2_WzYpKgC&printsec=frontcover&dq=isbn:0836218256&hl=&cd=1&source=gbs_api";
printType = BOOK;
publishedDate = "1988-01-01";
publisher = "Andrews McMeel Publishing";
ratingsCount = 18;
readingModes = {
image = 1;
text = 0;
};
title = "Something Under the Bed Is Drooling";
};
}
);
kind = "books#volumes";
totalItems = 1;
}
What I want to do is create an object from the items in this dictionary. This method needs to work generically for all books without crashing. Even if they are missing some of the attributes. The attributes I need to extract are:
-authors last name (Need for every author listed if there is more than one)
-authors first name (Need for every author listed if there is more than one)
-title
-description
-smallThumbnail
-thumbnail
-isbn_10 identifier
-category
From these I am going to create a "book" object. i will also create an NSSet of Authors, and each Author has a lastName and firstName
How do I go about doing this?
You should be able to safely use NSDictionary's -valueForKeyPath: to retrieve each value from an item dict:
NSArray *names = [itemDict valueForKeyPath:#"volumeInfo.authors"];
NSString *title = [itemDict valueForKeyPath:#"volumeInfo.title"];
...

Getting specific value from string

In My Application i am Using ArcGIS . in that one i want Search one place and get the places related to that name. Now I want to Parse all the address of that places and put them in a table View. after typing the address and after i press search Button i will get all the Markers on the Map. Now i'm trying to get the complete address of the Place But i was unable to do this.I want to get "place_addr" value from the below string can any one please help me how can i get that value in ios
AGSFindLocationResult name=Disneyland, extent=AGSEnvelope: xmin = -13129988.221853, ymin = 4000701.846518, xmax = -13124422.247314, ymax = 4007401.106877, spatial reference: [AGSSpatialReference: wkid = 102100, wkt = null], graphic=geometry: AGSPoint: x = -13127204.667522, y = 4004050.640580, spatial reference: [AGSSpatialReference: wkid = 102100, wkt = null], symbol: { AGSPictureMarkerSymbol: imageName: BluePushpin.png, width: 36.000000, height: 36.000000 }, attributes: {
AddBldg = "";
AddNum = "";
AddNumFrom = "";
AddNumTo = "";
"Addr_type" = POI;
City = Anaheim;
Country = USA;
DisplayX = "-117.923687";
DisplayY = "33.815467";
Distance = 0;
LangCode = "";
"Loc_name" = "Gaz.WorldGazetteer.POI2";
"Match_addr" = Disneyland;
Nbrhd = "";
Phone = "(714)781-4565";
PlaceName = Disneyland;
"Place_addr" = "1313 S Disneyland Dr Anaheim, CA 92802";
Postal = "";
PostalExt = "";
Rank = "2.5";
Region = California;
Score = 100;
Side = "";
StAddr = "";
StDir = "";
StName = "";
StPreDir = "";
StPreType = "";
StType = "";
Subregion = Orange;
Type = "Amusement Park";
URL = "";
X = "-117.923687";
Xmax = "-117.898691";
Xmin = "-117.948691";
Y = "33.815467";
Ymax = "33.84047000000002";
Ymin = "33.79047";
}, visible: 1
IF what you're getting back really is a string, then you should look at the string searching methods like rangeOfString.
That will return an NSRange that contains your label, "place_addr".
Then you'd want to search from that point forward for a semicolon, using the related method rangeOfString:options:range:, that searches in a specific range of a string.
Finally, you'd need to calculate a range for the contents, that would be 5 characters past the end of the NSRange of "place_addr", and up to, but not including, the final semicolon.
Then you'd use substringWithRange to extract the string who's range you calculated above.
Give that a try, and come back if you have trouble.
Please try the code below
- (NSArray *)findKey:(NSString *)key inString:(NSString *)allString
{
NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:1];
NSArray *splitArray = [allString componentsSeparatedByString:#";"];
for (NSString *s in splitArray) {
NSArray * keyValueArry = [s componentsSeparatedByString:#"="];
if([keyValueArry count] > 1)
{
NSString *_key = [keyValueArry objectAtIndex:0];
NSString *_value = [keyValueArry objectAtIndex:1];
if([_key isEqualToString:key])
{
[result addObject:_value];
}
}
}
return result;
}
where key is place_addr, and allString is as your sample string.

Export to excel losses leading zero in mvc4

i am working on mvc4 project.I have having issue with export to excel code.I have employee id that is varchar field... and have leading zero ie : 0289707,2909878 etc..
So when i export data to excel it looses leading zero..
So how do i export data as it is ??
Controller code is as below :
public ActionResult ExportToExcel(string strStartDate, string strEndDate)
{
try
{
GridView gridView = new GridView();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "EmployeeReport " + Helper.GetBrazilTime(DateTime.UtcNow).ToString() + ".xls"));
Response.ContentType = "application/ms-excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
gridView.AllowPaging = false;
DateTime startDate = Convert.ToDateTime(strStartDate);
DateTime endDate = Convert.ToDateTime(strEndDate);
if (Helper.CurrentCulture == "pt-BR")
{
startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0, DateTimeKind.Utc);
endDate = new DateTime(endDate.Year, startDate.Month, endDate.Day, 0, 0, 0, DateTimeKind.Utc);
}
gridView.DataSource = ReportExecutor.GetEmployeeReportExportData(startDate, endDate);
gridView.DataBind();
//This will change the header background color
gridView.HeaderRow.Style.Add("background-color", "#FFFFFF"); //
//This will apply style to gridview header cells
for (int index = 0; index < gridView.HeaderRow.Cells.Count; index++)
{
gridView.HeaderRow.Cells[index].Style.Add("background-color", "#778899"); //Light Slate Gray
gridView.HeaderRow.Cells[index].Style.Add("foreground-color", "#ffffff"); // White
}
gridView.HeaderRow.Cells[0].Text = #Resources.Resource.ShopName;
gridView.HeaderRow.Cells[1].Text = #Resources.Resource.MachineName;
gridView.HeaderRow.Cells[2].Text = #Resources.Resource.ProjectIDName;
gridView.HeaderRow.Cells[3].Text = #Resources.Resource.BaseActivity;
gridView.HeaderRow.Cells[4].Text = #Resources.Resource.EmployeeID;
gridView.HeaderRow.Cells[5].Text = #Resources.Resource.EmployeeName;
gridView.HeaderRow.Cells[6].Text = #Resources.Resource.RunTime;
gridView.HeaderRow.Cells[7].Text = #Resources.Resource.SetUp;
gridView.HeaderRow.Cells[8].Text = #Resources.Resource.TearDown;
gridView.HeaderRow.Cells[9].Text = #Resources.Resource.Work;
gridView.HeaderRow.Cells[10].Text = #Resources.Resource.Rework;
gridView.HeaderRow.Cells[11].Text = #Resources.Resource.LunchHours;
gridView.HeaderRow.Cells[12].Text = #Resources.Resource.MaintenanceHours;
gridView.HeaderRow.Cells[13].Text = #Resources.Resource.QualityProblemHours;
gridView.HeaderRow.Cells[14].Text = #Resources.Resource.LOMHours;
gridView.HeaderRow.Cells[15].Text = #Resources.Resource.UDCIdle;
gridView.HeaderRow.Cells[16].Text = #Resources.Resource.UDCOthers;
gridView.HeaderRow.Cells[17].Text = #Resources.Resource.ActualShiftHours;
gridView.HeaderRow.Cells[18].Text = #Resources.Resource.Overtime;
int index2 = 1;
//This will apply style to alternate rows
foreach (GridViewRow gridViewRow in gridView.Rows)
{
//gridViewRow.Attributes.Add("class", "textmode");
gridViewRow.BackColor = Color.White;
if (index2 <= gridView.Rows.Count)
{
if (index2 % 2 != 0)
{
for (int index3 = 0; index3 < gridViewRow.Cells.Count; index3++)
{
gridViewRow.Cells[index3].Style.Add("background-color", "#e6e6fa");// Lavender
//gridViewRow.Cells[index3].Style.Add("class", "textmode");// Apply text style to all rows
}
}
}
index2++;
}
gridView.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
}
catch
{
}
return null;
}
For i As Integer = 0 To GridView1.Rows.Count - 1
//Apply text style to each Row.cell
//The attribute must be "text" not "textmode" and it must be applied to the cells
For j As Integer = 0 To GridView1.Rows(i).Cells.Count - 1
GridView1.Rows(i).Cells(j).Attributes.Add("class", "text");
Next
Next

Parsing Vimeo Json response in ios

I got this json response
{
"generated_in" = "0.0283";
stat = ok;
videos = {
"on_this_page" = 3;
page = 1;
perpage = 50;
total = 3;
video = (
{
"embed_privacy" = anywhere;
id = 73198189;
"is_hd" = 1;
"is_watchlater" = 0;
license = 0;
"modified_date" = "2013-08-27 01:29:16";
owner = 20303618;
privacy = anybody;
title = Untitled;
"upload_date" = "2013-08-27 00:57:36";
},
{
"embed_privacy" = anywhere;
id = 73197989;
"is_hd" = 0;
"is_watchlater" = 0;
license = 0;
"modified_date" = "2013-08-27 01:24:17";
owner = 20303618;
privacy = anybody;
title = sample2;
"upload_date" = "2013-08-27 00:52:40";
},
{
"embed_privacy" = anywhere;
id = 72961770;
"is_hd" = 0;
"is_watchlater" = 0;
license = 0;
"modified_date" = "2013-08-23 05:57:48";
owner = 20303618;
privacy = anybody;
title = sample;
"upload_date" = "2013-08-23 05:25:44";
}
);
};
}
when i am trying to parse it for the video id.
The technique i used is
i converted that json into NSDictionary jsondata and
NSString *videoid = [[[jsondata objectForKey:#"videos"]valueForKey:#"video"]valueForKey:#"id"];
NSLog(#"video string is %#",videoid);
the result is:
(
73198189,
73197989,
72961770
)
but i am not able to access the normal string functions on that string to retrieve the id's.
it is saying an error unrecognized selector was sent.
Is there a better way to parse that string, i tried google but every post says the same approach.
You not getting a string but an array of strings, the JSON response holds mutiple videos. The code you used will retrieve all the id of all the videos.
You can loop thru the found videos like:
NSArray *videoIdArray = [jsondata valueForKeyPath:#"videos.video.id"];
for(NSString *videoId in videoIdArray) {
NSLog(#"video string is %#",videoId);
}

Resources