I am working on Enterprise Architect C# add-ins. I am trying to add hyperlink to another package in element notes through add-ins as shown below:
I found the code for adding hyperlink in element to package here : https://www.sparxsystems.com/forums/smf/index.php?topic=4068.0
and tried the following code:
EA.Package parentPkg = Session.Repository.GetPackageByID(currentPackage.ParentID);//target package
hyperlink = currentPackage.Elements.AddNew("$package://"+parentPkg.PackageGUID, "Text"); //adding hyperlink
hyperlink.Update();
hyperlink.Subtype = 19;
hyperlink.Update();
hyperlink.Notes = parentPkg.Name;
hyperlink.Update();
demoElement.Notes = "test for packages hyperlinks" + hyperlink; //demo element's notes must contain hyperlink to target package
mobjElement.Update();
It is not displayed as hyperlink here but as System.__ComObject.
Kindly help. Thanks in advance.
As Geert and Thomas Suggested if you just need to make hyperlink in notes just add a herf tag ti that word like below
This is a <a href="$element://{64162D99-026B-40b3-914C-2CC009943540}"><font
color="#0000ff"><u>Hyperlink</u></font> </a> Example
and the output in notes will be like
In API you can just add the link text in notes property of any class.
switch ( treeSelectedType )
{
case otElement :
{
// Code for when an element is selected
var theElement as EA.Element;
theElement = Repository.GetTreeSelectedObject();
theElement.Notes="This is a <font color=\"#0000ff\"><u>Hyperlink</u></font> Example";
theElement.Update();
theElement.Refresh();
break;
}
I tried (as Geert suggested) the following code snippet (sorry for the Perl):
my $e = $rep->getElementByGuid("{92EF2B52-B75E-454d-AD03-5BDC12256A36}");
$e->{notes} = "<font color=\"#0000ff\"><u>Link name</u></font>";
$e->Update();
Just replace the GUID and the display name and you have a hyperlink to a package. Note that the above string has some escape chars, so here's the raw text:
<font color="#0000ff"><u>Link name</u></font>
Related
I am working n exporting excel using Aspose.Cells. In that i need to show some HTML formatted comment in specific column. But when i set note in comment using HTML string then it automatically modify that HTML. I am usiing below code
Workbook workbook = GetExcelWorkbook<AuditLogExport>(auditLogExportData, templatePath);
CommentCollection comments = workbook.Worksheets[0].Comments;
for (int i = 0; i < exportData.Count; i++)
{
if (exportData[i].IsDetailedChange)
{
int commentIndex = comments.Add(string.Format("E{0}", (i + 2)));
Aspose.Cells.Comment comment = comments[commentIndex];
**comment.HtmlNote = GetAuditLogCommentNote(exportData[i]);**
comment.WidthCM = 8.0;
comment.HeightCM = 20.0;
}
}
public static string GetAuditLogCommentNote(AuditLog auditLog)
{
string note = string.Empty;
note = "<table width='400px' style='border:solid 1px black'><tr><th>Changed Field</th><th>Previous</th><th>Current</th></tr>";
foreach (var history in auditLog.DetailChanges)
{
note += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", history.FieldName, history.FirstChange, history.LastChange);
}
note += "</table>";
return note;
}
When i am assigning value to HtmlNote property of comment it automatically change html with font tags and strip all table tags from string. Can someone please help on this?
Update-1
Well, we think, your requirement is not achievable using Microsoft Excel. If something is not possible with Microsoft Excel, then it will also not be possible with Aspose.Cells or any other API automatically.
Please see the following screenshot. It shows how your HTML looks like when it is viewed in Web Browser and when it is copied/pasted to Excel comment.
If you think, your requirement is doable using Microsoft Excel, please provide us your sample Excel file that you have created manually using Microsoft Excel. We will check it and investigate this issue further.
Update-2
We tested this issue with the following code and found that if we try to create comment with HtmlNote property, it does not work.
We have logged this issue in our database for investigation and for a fix. Once, the issue is resolved, we will update you in this post.
This issue has been logged as
CELLSNET-46210 - Creating Comment using HtmlNote property does not work
C#
Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[0];
int idx = ws.Comments.Add("E4");
Comment cm = ws.Comments[idx];
//cm.HtmlNote = "<Font Style=\"FONT-WEIGHT: bold;FONT-FAMILY: Tahoma;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;\">Heading: </Font><Font Style=\"FONT-FAMILY: Tahoma;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;\">This is some para. </Font><Font Style=\"FONT-WEIGHT: bold;FONT-FAMILY: Tahoma;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;\">Heading2:</Font><Font Style=\"FONT-FAMILY: Tahoma;FONT-SIZE: 9pt;COLOR: #000000;TEXT-ALIGN: left;\"> This is some para2.</Font>";
cm.HtmlNote = new Workbook("input.xlsx").Worksheets[0].Comments[0].HtmlNote;
cm.IsVisible = true;
wb.Save("output.xlsx");
Update-3
Your issue logged as CELLSNET-46210 has been fixed in Aspose.Cells for .NET v18.7. Please download it from this link.
https://www.nuget.org/packages/Aspose.Cells/18.7.0
Note: I am working as Developer Advocate at Aspose
Currently i am working with c# project.In windows.I have a text file that contains the following text.
I want to grab this http://google.com/en/login
or
just google.com
Sometime the url may changes like below
SiteURL=http:// google.com/en/login
SiteURL=https:// google. com/en/login
SiteURL=http:// www.google. com/en/login
SiteURL=https:// www.google. com/en/login
Note: There are no spaces in url site not allowing me to post more than 2 links.
Even though i want to grab text after siteurl= or just google.com
Thanks
I have zero knowledge in regex.This is a small part what i need in my project.Thanks
The below text present in text file.While reading the text file i want to garb that url.Thank you very much
[Wordlist]
UserIndex=1
PassIndex=2
EmailIndex=0
543835182C9E9FFF099CD106D4253D3A=100
[Settings]
SiteURL=http://google.com/en/login
Timeout=20
WaitBot=0
ResolveHost=0
ComboFilter=0
ComboMode=0
EmailFilter=0
EmailMode=0
UsernameStart=6
UsernameEnd=8
InvalidChars=
AllowedChars=
Letters=0
Digits=0
Alpha=0
Email=0
LowerUpper=0
LetterDigit=0
SpeciaChar=0
PasswordStart=6
PasswordEnd=8
PasswordInvalidChars=
PasswordAllowedChars=
PasswordLetters=0
PasswordDigits=0
PasswordAlpha=0
PasswordEmail=0
PasswordLowerUpper=0
PasswordLetterDigit=0
PasswordSpeciaChar=0
ProxyActivate=10
ProxyRatio=4
ProxyCombo=0
WaitTime=1
BanWindowWidth=1
BanWindowRatio=10
BanWindowProxies=10
blnNoProxies=1
HTTPHeader=<ACTION> <FORM ACTION> <HTTP VERSION>|Accept: */*|User-Agent: <USER AGENT>|Host: <HOST>|Pragma: no-cache|Connection: keep-alive|
RequestMethod=2
Referer=0
POSTData=login=<USER>&password=<PASS>&referer=
[Fake]
AfterFP=1
blnSuccess=0
SuccessRetries=3
blnProcessErrors=0
blnCompleteNot=1
EnableConHits=0
ConHits=0
FollowRedirect=1
EnableConLength=0
ConLength=-1
SourceTags=1
UserField=0
HTTPFollow=1
blnForbToOK=0
ForbToOkLength=1000
blnBadOcrCode=0
BadOcrCodeRetries=3
[Keywords]
EnableHeaderSuccess=0
EnableHeaderBan=0
EnableHeaderFail=0
EnableHeaderRetry=0
HeaderSuccess=
HeaderBan=
HeaderFail=
HeaderRetry=
EnableGlobalSourceRetry=1
EnableSourceSuccess=1
EnableSourceBan=0
EnableSourceFail=1
EnableSourceRetry=0
SourceSuccess=>Logout
SourceBan=
SourceFail=Fail login
SourceRetry=
[Form]
IAParse=0
LoginPostData=
LoginMethod=1
LoginHeader=0
Action=http://google.com/en/login
Username=login
Password=password
Email=
AddData=referer=
CustomData=
NoIndex=
Cookie=identity=f03982a8f9c847e9a23cb818912f7a51; symfony=0el04cmspgogapkkt6k26uo3b4
IAction=-1
IUser=-1
IPass=-1
IEmail=-2
ICaptcha=-1
ReqReferer=
ReqCookie=
AjaxURL=
AjaxPOSTData=
AjaxData=
AjaxParsingCode=
RefData=
ParsingCode=
FormRedirectUrl=
RedPostData=
RedKeys=
DataDesc=Cracked BY ***************** Team = Your account is&Valid to
CaptureParsingCode=s: |<|#00|#00|0|#00|#00|0&o: | |#00|#00|0|#00|#00|0
RefreshSession=0
RefreshCookie=0
FormHeader=0
AjaxHeader=0
RedHeader=0
IAMethod=2
POSTMethod=2
RedMethod=1
ImageAfterAjax=0
blnBasic=0
FollowRedirectsOnIA=0
FollowRedirectsOnRed=1
[Ajax]
Variables=
PostElements2=
RedURL=
[OCR]
OCRMode=0
URLMode=0
ImageURLID=||
Captcha=
OCRKey=
RefreshCaptcha=0
blnContrast=0
blnBrightness=0
blnSaturation=0
blnThreshold=0
blnInvert=0
blnNoise=0
blnIsolate=0
blnResize=0
blnBorder=0
blnCharExtract=0
blnRemoveColors=0
blnStringFilter=0
blnLetter=1
blnDigits=1
blnBlur=0
blnReconstruct=0
blnLower=0
blnUpper=0
blnRemoveLines=0
blnMultiChar=0
blnCharTable=0
blnPalette=0
blnCharResize=0
blnCharSubExtraction=0
blnThreeImages=0
blnGif=0
blnCompute=0
blnBorderPre=0
Contrast=0
Brightness=0
Saturation=0
Threshold=0
Noise=1
Isolate=1
Resize=2
BorderLeft=0
BorderTop=0
BorderRight=0
BorderBottom=0
CharExtractMinBlack=0
CharExtractMaxBlack=1
CharExtractMinWidth=1
CharRotateMax=0
CharRotateSteps=5
MinLength=1
MaxLength=10
BlurRadius=1
CharExtractMaxWidth=33
CharWidthMinBlack=2
CharSpace=1
Range=0
InvertDensity=0
InvertLength=20
LineCurvatureMax=4
LineWidthMax=13
CharResize=1
CharHeight=13
GifStart=2
GifOffset=2
BorderLeftPre=0
BorderTopPre=0
BorderRightPre=0
BorderBottomPre=0
CharBorderH=5
CharBorderV=5
CharRotateBorder=5
CharExtractMinHeight=1
VerticalRejoin=30
CharExclude=
SpecialChars=
Colors=
Colors2=
Lines=Min Length: 2, Max Width: 5, Horizzontal
Language=eng
var pattern = #"(?<=SiteURL=).+";
string text = System.IO.File.ReadAllText(path); //your path needs to be added here (e.g. #"C:\Users\userx\Downloads\file.txt")
var match = System.Text.RegularExpressions.Regex.Match(text, pattern);
The link you're looking for is stored in the variable called "match".
I'm attempting to use RazorEngine 3 to insert HTML elements into a template. When I try this, the resulting string (used later as HTML) ends up displaying the HTML markup rather than utilizing it to render the page.
Code:
var linkText = new HtmlString("" + linkName + "");
string result = Razor.Parse(template, new {MyLink = linkText});
Template file:
Link to file: #Model.MyLink
Resulting HTML:
Link to file: <a href=http://blah.com>Blah link</a>
This functionality was working fine with RazorEngine 2, but I had to upgrade due to another glitch. Additionally, this is a console application so adding #Raw functionality might be complicated.
The answer ended up being to use a string type variable that is passed into the template. The template, in turn uses the Raw() method as seen below.
Code:
string linkText = "" + linkName + "";
string result = Razor.Parse(template, new {MyLink = linkText});
Template File:
Link to file: #Raw(#Model.MyLink)
Hi all,
I want to add style attributes in my HTML tags using C#. Please find the below code.
StringBuilder mailBody = new StringBuilder();
mailBody.AppendFormat("<html>");
mailBody.AppendFormat("<p>Please note:</p>");
mailBody.AppendFormat("<p> " + data + " folder no longer exists on the network. Please review at your earliest convenience. </p>");
mailBody.AppendFormat("<br/>");
mailBody.AppendFormat("<p>Thank you</p>");
mailBody.AppendFormat("<p>Development Team</p>");
mailBody.AppendFormat("</html>");
emailBody = mailBody.ToString();
And the output is :
The text displayed in the image font style is "Time New Roman". How could I change that to display in any other font type. How could I add that in above HTML tags.
Thanks in advance.
<p><span style="font-family:Verdana">Please note:</span></p>
http://www.w3schools.com/html/html_styles.asp
Add the style to the tag, like this:
<p style="font-family:courier">Please note:</p>
Check for more info here: http://w3schools.com/html/html_styles.asp
<p style="font-family:arial black">Please note:</p>
pls go through this link for more info
http://w3schools.com/html/html_styles.asp
An even easier way would be to put it in the CSS
BODY P
{
}
Then you wouldnt need to put it into all the P tags
Or if you want to make it only apply to a section
You should surround this in a div and then
.<DivClassName> P
{
}
I would do this, so you're taking advantage of CSS:
var mailBody = new StringBuilder();
// put in the font(s) you'd like to use. If font 1 isn't installed,
// it will move on to the next font in line, and so forth.
var font = "Arial, Calibri, 'Trebuchet MS', sans-serif";
// the color of the text. If you'd like to use more colors, take
// advantage of CSS classes.
var color = "red";
mailBody.Append("<html><head>");
mailBody.Append("<style type=\"text/css\">");
mailBody.AppendFormat("body { font-family: {0}; color: {1}; }",
font, color);
mailBody.Append("</style>");
mailBody.Append("<p>Please note:</p>");
mailBody.AppendFormat("<p>{0} folder no longer exists on the network. Please review at your earliest convenience.</p>",
data);
mailBody.Append("<br/>");
mailBody.Append("<p>Thank you</p>");
mailBody.Append("<p>Development Team</p>");
mailBody.Append("</html>");
emailBody = mailBody.ToString();
Also note, you don't need to use the AppendFormat method unless you plan on passing in parameters into the tokens embedded in the string ({0}, {1} etc).
I got a user control which implements a reference to a css file, now I want to use this user control many times on page, and this will lead to duplication of inclusion of the css file.
With javascript files it is simple by using the ScriptManager.
So what is your suggestion for a solution or similar approach to the ScriptManager?
Here's a technique I've used before, although it may not be the best one:
Dim cssLink As String = String.Format("<link rel='stylesheet' type='text/css' href='{0}/css/cssLink.css' />", Request.ApplicationPath)
If (From c As LiteralControl In Page.Header.Controls.OfType(Of LiteralControl)() Where c.Text = cssLink).Count = 0 Then
Page.Header.Controls.Add(New LiteralControl(cssLink))
End If
As q is tagged c# thought I may as well paste in c# version from helper class:
public static void AddStyleLink(string href)
{
Page page = (Page)HttpContext.Current.CurrentHandler;
var existing =
(from c
in page.Header.Controls.OfType<HtmlGenericControl>()
where c.Attributes["href"] == href
select c).FirstOrDefault();
if (existing == null)
{
HtmlGenericControl link = new HtmlGenericControl("link");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", href);
page.Header.Controls.Add(link);
}
}
There is no easy way to check if the styles are registered to the page like ClientScript utility.
If you register your styles as an external css file to page like that :
HtmlLink link = new HtmlLink();
link.Href = relativePath;
link.Attributes["type"] = "text/css";
link.Attributes["rel"] = "stylesheet";
Page.Header.Controls.Add(link);
You can then check if it exists by looping the page header's Controls collection and looking for the path of the CSS file.