TextBox txtContent = new TextBox();
SPList announcementList = mySite.Lists["Announcements"];
SPListItem getAnnouncement = announcementList.Items[0];
txtContent.Text = getAnnouncement["Body"].ToString();
this gives output as
<div class="ExternalClass61EB4AB2F639401D9141EADFC30FEDFE">
<p>Please follow plan of action.</p>
</div>
I want output as
"Please follow plan of action."
Please Guide.
Use SPFieldMultiLineText like the following:
SPListItem getAnnouncement = announcementList.Items[0];
SPFieldMultiLineText bodyField = getAnnouncement.Fields.GetField("Body") as SPFieldMultiLineText;
string txt = bodyField.GetFieldValueAsText(getAnnouncement["Body"]);
string html = bodyField.GetFieldValueAsHtml(getAnnouncement["Body"]);
If you're looking to remove the HTML from the content, this answer will help you:
How can I strip HTML tags from a string in ASP.NET?
There are a number of solutions there, such as the one with Regex. You would just need this line of code:
txtContent.Text=WebUtility.HtmlDecode(Regex.Replace(getAnnouncement["Body"].ToString(), "<[^>]*(>|$)", string.Empty))
SPHttpUtility.ConvertSimpleHtmlToText(text, text.Length - 1);
Related
Sorry in advance if I’m not phrasing this question correctly. I know nothing about InDesign scripting, but this would solve a workflow problem I’m having at my company, so I would appreciate any and all help.
I want to find all strings in an InDesign file that are between angle brackets (i.e. <variable>) and export that out into a list. Ideally this list would be a separate document but if it can just be dumped into a text frame or something that’s fine.
Any ideas on how to do this? Thank you in advance for any and all help.
Here is something simple:
app.findGrepPreferences=NothingEnum.NOTHING; //to reset the Grep search
app.findGrepPreferences.findWhat = '<[^<]+?>'; //the word(s) you are searching
var fnd = app.activeDocument.findGrep (); //execute search
var temp_str = ''; //initialize an empty string
for (var i = 0; i < fnd.length; i++) { //loop through results and store the results
temp_str += fnd[i].contents.toString() + '\r'; // add next found item text to string
}
var new_doc = app.documents.add (); //create a new document
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS; //set measurement units to points
var text_frame = new_doc.pages[0].textFrames.add({geometricBounds:[0,0,100,100]});// create a new text frame on the first page
text_frame.contents = temp_str; //output your text to the text frame in the new document
For more data see here.
I have a self defined web control.
Some code in a loop:
double cellHeight = 12.34;
Label dcell = new Label();
dcell.Style["height"] = cellHeight + "pt";
dcell.Text = cellHeight;
If I use CultureInfo("cs-CZ")
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("cs-CZ");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("cs-CZ");
after render, the html came out
<span style="height:11,75pt">11,75</span>
actually what I expected is:
<span style="height:11.75pt">11,75</span>
height:11,75pt is totally wrong when rendered in browser, actually the browser does not consider 11,75pt as 11.75pt.
However I need to keep the text field displayed based on culture info: the text field displays 11,75 that is correct.
So this is the problem - how can I fix?
You need to convert double to string properly, for example:
dcell.Style["height"] = cellHeight.ToString("F", CultureInfo.CreateSpecificCulture("eu-ES")) + "pt";
Or like this:
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.NumberDecimalSeparator = ".";
dcell.Style["height"] = cellHeight.ToString(nfi) + "pt";
I am using the code below for saving uploaded picture and makigna thumbnail but it saves a filename without the extension to the database, therefore, I get broken links. How can I stop a strongly typed dataset and dataadapter to stop removing the file extension? my nvarchar field has nvarchar(max) so problem is not string length.
I realized my problem was the maxsize in the dataset column, not sql statement parameter, so I fixed it. You may vote to close on this question.
hasTableAdapters.has_actorTableAdapter adp1 = new hasTableAdapters.has_actorTableAdapter();
if (Convert.ToInt16(adp1.UsernameExists(username.Text)) == 0)
{
adp1.Register(username.Text, password.Text,
ishairdresser.Checked, city.Text, address.Text);
string originalfilename = Server.MapPath(" ") + "\\pictures\\" + actorimage.PostedFile.FileName;
string originalrelative = "\\pictures\\" + actorimage.FileName;
actorimage.SaveAs(originalfilename);
string thumbfilename = Server.MapPath(" ") + "\\pictures\\t_" + actorimage.PostedFile.FileName;
string thumbrelative = "\\pictures\\t_" + actorimage.FileName;
Bitmap original = new Bitmap(originalfilename);
Bitmap thumb=(Bitmap)original.GetThumbnailImage(100, 100,
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback),
IntPtr.Zero);
thumb=(Bitmap)original.Clone(
new Rectangle(new Point(original.Width/2,original.Height/2), new Size(100,100)),
System.Drawing.Imaging.PixelFormat.DontCare);
/*
bmpImage.Clone(cropArea,bmpImage.PixelFormat);
*/
thumb.Save(thumbfilename);
adp1.UpdatePicture(originalrelative, thumbrelative, username.Text);
LoginActor();
Response.Redirect("Default.aspx");
}
}
Looks like the problem is you are using HttpPostedFile.FileName property, which returns fully-qualified file name on the client. So, this code string originalfilename = Server.MapPath(" ") + "\\pictures\\" + actorimage.PostedFile.FileName; generates something like this:
c:\inetpub\pictures\c:\Users\Username\Pictures\image1.jpg
Use FileUpload.FileName property everywhere and you will probably get what you want.
Use this to get Image or file extension :
string Extension = System.IO.Path.GetExtension(FileUpload.FileName);
i have this code
MasterSoapClient sp = new MasterSoapClient();
MasterData[] lstMasterData = sp.GetActivityType(stid, null, 1);
grdEditActivityType.DataSource = lstMasterData;
grdEditActivityType.DataBind();
Session["opType"] = 2;
txtActivityCode.Text = lstMasterData.ToString();
txtActivityCode.DataBind();
here i called web service and put all data in this Gridview "grdEditActivityType "
and already workin
but there is column of lstMasterData i want to put it in the text box out of the grid
how i can do this ?
txtActivityCode.Text is a Property that you can use to assign a text value to the TextBox.
If you use txtActivity.Text = " some input "; Your textbox will contain the text " some input ".
You don't need to Bind txtActivityCode afterwards.
Having this clarified the next step is to create the string you want using to assign to the text box.
string s = "";
foreach( var masterData in lstMasterData )
{
s += masterData.SomeProperty; // s += masterData.ToString(); maybe, it depends on what do you want to put in the textbox;
}
txtActivityCode.Text = s;
And that's all.
I would suggest to start look more over ASP.NET tutorials to understand better how this framework works.
I want to select one item in drop down list in ASP.NET written with VB.NET - I have values and texts in listbox like this:
Volvo
Audi
etc...
But values coming from other place in upper case... VOLVO, AUDI..
This code:
dropdownlist.FindByValue("CAPITAL")
Is not working and giving null for Volvo.. please help.
One way would be LINQ:
Dim volvoItem = dropdownlist.Items.Cast(Of ListItem)().
FirstOrDefault(Function(i) i.Text.Equals("Volvo", StringComparison.InvariantCultureIgnoreCase))
C#:
var volvoItem = dropdownlist.Items.Cast<ListItem>()
.FirstOrDefault(i => i.Text.Equals("Volvo", StringComparison.InvariantCultureIgnoreCase));
This worked for me
foreach(ListItem li in dropdownlist.Items)
{
if (String.Compare(li.Text, myLabel.Text, true) == 0)
myCustomValidator.IsValid = false; // Match Found !
}
Like Tim said LINQ would be you answer.
in C# try the following:
var item = dropdownlist.Items.Cast<ListItem>().SingleOrDefault(li =>
li.Text.ToUpper() == "VOLVO");
Additional variants, using framework CI comparison. VB:
uiList.Items.Cast(Of ListItem)
.FirstOrDefault(Function(i) i.Text.Equals(comparand, StringComparison.InvariantCultureIgnoreCase))
C#:
uiList.Items.Cast<ListItem>()
.FirstOrDefault(i => i.Text.Equals(comparand, StringComparison.InvariantCultureIgnoreCase));
You could also use CurrentCultureIgnoreCase depending on your requirements. These are generally safer than comparing with ToUpper/ToLower, because some cultures have unexpected casing rules.