Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Saturday, March 31, 2012

System.Drawing.Text font question

Hello,

I've looked for answer to this everywhere but with no luck..

I need to dynamically create graphic text from database values. I've got this working fine if I use arial as the font but I want to use another font.

Now - presumably I can use any font installed on the server? But it doesn't seem to work. I want to use a font called blurLight but it just outputs in arial (I think - it's a standard font anyway)

Is there anything else I need to do to make other fonts available to asp.net other than just installing them on the server???

Thank you.Post some code so we can have a looksie
Alright - I will

<%@. Page Language="VB" Debug="True" %>
<%@. Import Namespace="System.Drawing" %>
<%@. Import Namespace="System.Drawing.Imaging" %>
<%@. Import Namespace="System.Drawing.Text" %>
<%
' Declare Vars
Dim objBMP As System.Drawing.Bitmap
Dim objGraphics As System.Drawing.Graphics
Dim objFont As System.Drawing.Font

objBMP = New Bitmap(100, 30)

objGraphics = System.Drawing.Graphics.FromImage(objBMP)

objGraphics.Clear(Color.Green)

objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias

objFont = New Font("Arial", 16, FontStyle.Bold)

objGraphics.DrawString("Hello World", objFont, Brushes.White, 3, 3)

Response.ContentType = "image/GIF"
objBMP.Save(Response.OutputStream, ImageFormat.Gif)

objFont.Dispose()
objGraphics.Dispose()
objBMP.Dispose()
%

That code works fine but when I replace Arial with the font I want to use - it doesn't work..

Any ideas??

System.FormatException

Hi Guys,

When I trying to execute this code,

insGrupo = Nothing
insGrupo = New Grupo(Short.Parse(0), TxtGrCoCodi.Text)

occurs the following error

System.FormatException: Sequence of entrance was not in a incorrect format.

Somebody knows what it can be this error?

---------------
Marcus Vincius M. Montezanodid you get help with this?

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Marcus Vincius" <marc.marcus@.bol.com.br> wrote in message
news:%23M9qgFe1DHA.4032@.tk2msftngp13.phx.gbl...
> Hi Guys,
> When I trying to execute this code,
> insGrupo = Nothing
> insGrupo = New Grupo(Short.Parse(0), TxtGrCoCodi.Text)
>
> occurs the following error
> System.FormatException: Sequence of entrance was not in a incorrect
format.
>
> Somebody knows what it can be this error?
>
> ---------------
> Marcus Vincius M. Montezano

Wednesday, March 28, 2012

System.IO.StreamReader is not returning single quotes from my file

I am using a System.IO.StreamReader to read a text file that was created
with Notepad. It is returning everything except the single quotes (at least
that is the only thing I have noticed it is not returning). The code I am
using is:
Dim poemstreamreader As System.IO.StreamReader
poemstreamreader = System.IO.File.OpenText(Global.Poems(poemtitle))
cellPoemText.Text = poemstreamreader.ReadToEnd()
poemstreamreader.Close()
I know that it is reading from the correct file, because it is returning all
the characters correctly, I simply need to know how to make it not discard
special characters such as single quotes. How do I do this? Thanks.
--
Nathan Sokalski
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/Nathan,
You mean something as

> cellPoemText.Text = poemstreamreader.ReadToEnd()
> poemstreamreader.Close()
cellPoemText.Text = cellPoemText.Text.Replace("'","")
I hope this helps,
Cor
"Nathan Sokalski" <njsokalski@.hotmail.com> schrieb
>I am using a System.IO.StreamReader to read a text file that was
> created with Notepad. It is returning everything except the single quotes
> (at
> least that is the only thing I have noticed it is not returning).
> The code I am using is:
> Dim poemstreamreader As System.IO.StreamReader
> poemstreamreader =
> System.IO.File.OpenText(Global.Poems(poemtitle))
> cellPoemText.Text = poemstreamreader.ReadToEnd()
> poemstreamreader.Close()
>
> I know that it is reading from the correct file, because it is
> returning all the characters correctly, I simply need to know how to
> make it not discard special characters such as single quotes. How do
> I do this?
Don't know if this helps:
poemstreamreader = new io.streamreader(Global.Poems(poemtitle),
system.text.encoding.default)
This assumes ANSI encoding of the file.
Armin

Monday, March 26, 2012

System.Net.Mail & sending emails with line breaks

Hi,

When a client sends an email via a web form (text entered in a asp:TextBox server control), the email received has no line breaks, and it is displayed in one line. This has bad impact on email readability... How can one overcome this probelm?

Thank you,

Alon

If you are sending mail text in simple text format then you have to use System.Environment.NewLine to move rest text in next line.

SmtpMail.SmtpServer = "1.0.0.127";
MailMessage mm = new MailMessage();
mm.From = "bill@.microsoft.com";
mm.To = "job@.apple.com";
mm.Subject = "";
mm.Body = "line 1" + System.Environment.NewLine + "line 2";


Hi,

Thank you for your reply.

I forgot to metion that the mail is sent in HTML format:

mailMessage.IsBodyHtml =true;

Am I supposed to parse the user's message (the text in the TextBox control), chck for CRLF (or is it \n) and replace it with System.Environment.NewLine? Isn't there some standard way to send the email, as i is in the text box (multiline text box. It looks like a text area)?

Thank you,

Alon


Here is the modified code for HTML formated body

mm.Body = "line 1" + "<br>" + "line 2";

Rest of the code will remain same.


But how can I know where line1 ends and line2 starts? All I have is a string I get form TextBox.Text. From this string I cannot deduce where did the user hit return - it's a "flat" string.

A word about he context of this: this web form is a "Contact Us" page. The TextBox is a multiline text box, which serves as a free text input field.

Thank you,

Alon


As what Firoz said, you have to use the "<br />"

You will use the following code to replace each line in your textbox to break

Replace(textbox1.text, vbCrLf,"<br />")

HTH
Regards


Oooops, now I understand. It works. I thank the both of you.

Alon

Saturday, March 24, 2012

System.NullReferenceException

Hi,

Can somebody tell me how I get this error?

here is a snippet of the code:

<span class="Normal">
<asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
</span>
<% if (Context.User.Identity.Name == Label1.Text) { %>
<asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
<% } %>
<span class="ItemTitle">
<%# DataBinder.Eval(Container.DataItem,"Title") %>
</span
and here is the compiler error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Line 9: <asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
Line 10: </span>
Line 11: [RED MARKED]<% if (Context.User.Identity.Name == Label1.Text) { %>[\RED MARKED]
Line 12: <asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
Line 13: <% } %
Hope you can help me

regards

delleNullReferenceException's usually occur (in my experience anyway) when you have programmed an event to occur and presumed a variable/data source will be available and (for one of many possible reasons) it isn't.

I see you are using a databound control - have you told the control where to get it's data from? have called the DataBind event of the control?

Could you give us a bit more code?
Which line in the code is it telling you is causing this error?
You have to check Context.User for null before use
Hi,
Now I'm checking the value "Context.User.Identity.Name" for "null".

This was one problem I guess, because now I can build the project without an error,
but when I log in I still become an error.
I replaced my variables with constants to see if the function would work, and yes it is working.
The problem is that the value of Label1.Text cannot be compared with "Context.User.Identity.Name" for some reason.

Here is the new code:
<span class="Normal">
<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>
<asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
</span>
<% if (Context.User.Identity.Name != "") { %>
<% if (Context.User.Identity.Name == Label1.Text) { %>
<asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
<% } %>
<% } %>
<span class="ItemTitle">
<%# DataBinder.Eval(Container.DataItem,"Title") %>
</span
The error the compiler gives me is still the same in line 12:

Line 10: </span>
Line 11: <% if (Context.User.Identity.Name != "") { %>
Line 12: <% if (Context.User.Identity.Name == Convert.ToString(Label1.Text)) { %>
Line 13: <asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
Line 14: <% } %
Suggestions would be very appreciated.
thx.

System.NullReferenceException

Hi

I try to use this piece of code...


Dim CatID As Integer
CatID = (Request.QueryString("ID"))
CatID = 1
myProductsByCategory.Text = (GetProductsByCategory(CatID))

inside my Private Sub Page_Load but I get a System.NullReferenceException error from this.

What am I missing here?

Regards

MMy guess would be that the Querystring "ID" doesnt exist and you are getting a NULL exception when VB is converting it to an integer.
I hit Post too soon.. you might want to try to comment out the line that is assigning the value from the Querystring, since you are hardcoding it anyway (to 1).. see if thats the issue.
Hi

I comment out the querystring part, but that didn't help...

Regards

M
By the way... the function I try to call looks like this..

Function GetProductsByCategory(ByVal intID As Integer)

Dim connStr As String
connStr = ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_connStr")

Dim sb As StringBuilder = New StringBuilder
Dim sbOutput As String

Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim MyDataReader As SqlDataReader

MyConnection = New SqlConnection(connStr)
Try
MyConnection.Open()
MyCommand = New SqlCommand("dbo.p_ShowProductsByCategories", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure
MyCommand.Parameters.Add("@.ID", SqlDbType.Int, 4).Value = intID
MyDataReader = MyCommand.ExecuteReader()

sb.Append("<table width=""123"" border=""0"" cellpadding=""0"" cellspacing=""0"">")

While MyDataReader.Read
sb.Append("<tr>")
sb.Append("<td class=""menuitem"" onmouseover=""this.bgColor='#EEEEEE'"" onmouseout=""this.bgColor='#FDFDFD'"" style=""HEIGHT: 16px""> <a ref=""productdetail.aspx?ID=""" & (MyDataReader("ID")) & """>" & (MyDataReader("Description")) & "</a></td>" & vbCrLf)
sb.Append("</tr>")
End While

sb.Append("</table>")

sbOutput = sb.ToString()

MyDataReader.Close()
MyConnection.Close()

Catch ex As Exception
myErrorCode.Visible = True
myErrorCode.Text = (" ! An error occured <br> while accesing<br> products")
'Response.Write(ex.Message.ToString)
End Try
GetProductsByCategory = sbOutput
End Function

Regards

M
Ok.. is the runtime error not giving you the line number of the error? Are you sure the error is happening in those original 4 lines of code posted?
Try setting a breakpoint on the offending line and stepping through the GetProductsByCategory method to see where the problem lies.

(If you don't have Visual Studio you can use the CLR debugger in the .net framework SDK. You'll find it at

C:\Program Files\Microsoft.NET\FrameworkSDK\GuiDebug\DbgCLR.exe

You'll need to attach it to the aspnet_wp.exe process first. Choose "Debug Processes..." on the "Tools" menu, select aspnet_wp.exe and click "Attach".)
You are right, sorry! The line where the error is ...

myProductsByCategory.Text = (GetProductsByCategory(1))

Regards

M
Ok.. best case, your myProductsByCategory.Text is the problem.. worse case its a problem in the function, which is most likely the problem :)


connStr = ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_connStr")

Are yousure that you have this entry in your web.config file?
Yes I have, I use that part in the sub page_load so I know thats working.

Regards

M
Time to step through your code and see whats up then :)
Hmmm... I found the problem, I have forgotten to add the runat=server to the label holding the result.

Regards

M

Thursday, March 22, 2012

System.NullReferenceException: Object variable or With block variable not set

Please help i am getting the following error:
System.NullReferenceException: Object variable or With block variable not set

on this line.


TextBox1.Text = Trim(Row.Item("eng_lbl"))

I am trying to display the values of a record from the table in 4 text box fields.
I am new to asp.net. Please kindly help.


Dim mydataset As New DataSet
Dim myadapter As New SqlDataAdapter
Dim strId As String = Request.QueryString("lbl_Id")
Dim Row

Dim myCommand As New SqlClient.SqlCommand

Dim sql As String = "select * from tbl_labels where id =" & CInt(strId)

If Not Page.IsPostBack Then
MyCommand = New SqlCommand(sql, MyConnection)

myadapter = New SqlDataAdapter(myCommand)

mydataset.Clear()
myadapter.Fill(mydataset)

If mydataset.Tables(0).Rows.Count > 0 Then
TextBox1.Text = Trim(Row.Item("eng_lbl"))
TextBox2.Text = Trim(Row.Item("esp_lbl"))
TextBox3.Text = Trim(Row.Item("fr_lbl"))
TextBox4.Text = Trim(Row.Item("ger_lbl"))
End If
End If

You're not assign row to anything..

I.E.


Dim Row As DataRow

If mydataset.Tables(0).Rows.Count > 0 Then

Row = mydataset.Tables(0).Rows(0)

TextBox1.Text = Trim(Row.Item("eng_lbl"))

TextBox2.Text = Trim(Row.Item("esp_lbl"))

TextBox3.Text = Trim(Row.Item("fr_lbl"))

TextBox4.Text = Trim(Row.Item("ger_lbl"))

End If

Tuesday, March 13, 2012

system.text.stringBuilder

how can I add a variable in my system.text.stringbuilder

for example notice the example below

Dim myvar as string
myvar = "something"

Dim mystring as system.text.stringBuilder

mystring.append (" myvar ")

the above code does not work. It puts myvar as the literal text and not the actual value of the variable.

Please help with the syntax.You have to take the quotes out:


mystring.Append(myvar)

Thanks! Another question :) How can i retrieve an item from my datalist. For example I can get the Datakey but how can I get a particular item?

Here is the code I use to obtain the datakeys

Dim dlItem As DataListItem
For Each dlItem In detailsgrid.Items
' reference the TextBox
Dim txtItems As TextBox = CType(dlItem.FindControl("item_received"), TextBox)
' Grab the value
item_recieved = txtItems.Text
' Get the order number from DataKeys
order_num = detailsgrid.DataKeys(dlItem.ItemIndex).ToString()