Merging a large string including httpURl - c#

I am trying to add some large string into string type varriable.But it gives an error.
string SuccessUrl = "~/Customer/Success.aspx?URL=" + Server.UrlEncode("Transactionid="
+ Transactionid + "&Amount=" + Amount + "&Name=" + Name +
"&EmailOfPayer=" + EmailOfPayer + "&bussness=" + business + "&CompanyName=" + CompanyName
+ "&PaymentDate=" + paymentDateTime +"&SecuritiesandComplianceFee=" + SecuritiesandComplianceFee
+"&Status=" + Convert.ToInt32(Status) + "&BackmyUri=" + BackmyUri);
I have an error because of the last varriable i.e. BackmyUri. The varriable have the string value as given below.
string BackmyUri = "http://localhost:11181/Payment.aspx"
it gives an error .
Input string was not in a correct format.
Any kind of help will be appreciated.

Input string was not in a correct format. is most likely the default error message for int.Parse() and `Convert.ToInt32' . You should really check that. Another helpful thing for us would be to show us an example that makes it error, show the result of:
var x = "Transactionid=" + Transactionid + "&Amount=" + Amount + "&Name=" + Name +
"&EmailOfPayer=" + EmailOfPayer + "&bussness=" + business + "&CompanyName=" + CompanyName
+ "&PaymentDate=" + paymentDateTime +"&SecuritiesandComplianceFee=" + SecuritiesandComplianceFee
+"&Status=" + Convert.ToInt32(Status) + "&BackmyUri=" + BackmyUri

Related

Sum numbers in StreamWriter instead of writing next to each other in C#

I would like to write every data to a CSV file. Everything is working fine, but the numbers aren't adding up, they are written next to each other.
This part of the code:
file.WriteLine("\"1. koordinata:\"" + ";" + opening.rect_co_x + ";" + cord.y + ";" + opening.rect_co_z);
file.WriteLine("\"2. koordinata:\"" + ";" + opening.rect_co_x + opening.rect_width + ";" + cord.y + ";" + opening.rect_co_z);
Every property is a double, uint or int.
What I expect:
1 + 3 = 4
What I got:
1 + 3 = 13
+: mean a string concatenation, you can't calculate some of int inside string directly.
Try to use the following approach:
int a = 1, b = 3;
string str = $"a;{a + b};b"; // a;4;b
//or string.Format
string str2 = string.Format("a;{0};b", a + b);
You can change your code to:
file.WriteLine($"\"1. koordinata:\";{opening.rect_co_x };{cord.y};{opening.rect_co_z}");
file.WriteLine($"\"2. koordinata:\";{opening.rect_co_x + opening.rect_width};{cord.y};{opening.rect_co_z}");
I hope this help.

Yahoo Weather API by Lat and Lon

I'm writing a weather app in Xamarin.Form. I am using the Yahoo API. I have no problem getting the weather by the city name parameter. However, when I change the code to use longitude and latitude, the weather does not appear.
To download the weather I use the example from the page: https://developer.yahoo.com/weather/documentation.html#oauth-csharp
I processed it in the following way:
lSign = string.Format(
"format={0}&" +
"lat={1}&" +
"lon={2}&" +
"oauth_consumer_key={3}&" +
"oauth_nonce={4}&" +
"oauth_signature_method={5}&" +
"oauth_timestamp={6}&" +
"oauth_version={7}&" +
"u={8}",
cFormat,
szerokosc,
dlugosc,
cConsumerKey,
lNonce,
cOAuthSignMethod,
lTimes,
cOAuthVersion,
jednostka.ToString().ToLower()
(...)
url = cURL + "?lat=" + szerokosc + "&lon=" + dlugosc + "&u=" + jednostka.ToString().ToLower() + "&format=" + cFormat;
According to the documentation, lSign is used for authentication. It should not be changed, remove these "lat={1}&" + "lon={2}&" from that strings.
It says Please don't simply change value of any parameter without
re-sorting.
The location information should be involved in the request url and the authorization information is added in the header.
// Add Authorization
lClt.Headers.Add ( "Authorization", _get_auth () );
// The request URL
lURL = cURL + "?" + "lat=" + szerokosc + "&lon=" + dlugosc + "&format=" + cFormat;
Unfortunately, the simple removal of " lat = {1} & " + " lon = {2} & " from variable lSign does not solve the problem.
For example, to get weather data by the city name I use:
lSign = string.Format(
"format={0}&" +
"location={1}&" +
"oauth_consumer_key={2}&" +
"oauth_nonce={3}&" +
"oauth_signature_method={4}&" +
"oauth_timestamp={5}&" +
"oauth_version={6}&" +
"u={7}",
cFormat,
miasto,
cConsumerKey,
lNonce,
cOAuthSignMethod,
lTimes,
cOAuthVersion,
jednostka.ToString().ToLower()
and
url = cURL + "?location=" + Uri.EscapeDataString(miasto) + "&u=" + jednostka.ToString().ToLower() + "&format=" + cFormat;
and
string headerString = _get_auth();
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/" + cFormat;
webClient.Headers[HttpRequestHeader.Authorization] = headerString;
webClient.Headers.Add("X-Yahoo-App-Id", cAppID);
byte[] reponse = webClient.DownloadData(url);
string lOut = Encoding.ASCII.GetString(reponse);

Output showing System.Windows.Form.Label after every word

I am having a problem where the user enters his inputs into a text box (like a name). If the name is Jim Bob it will output like Jim System.Windows.Form.Label Bob System.Windows.Form.Label. I searched the properties tab and I am following along from the book but they do not have the same problem I have. I added some code below but I don't think it has anything to do with the problem.
string output;
output = textBoxPrefT.Text + ". " + textBoxFirstN + " " + textBoxMiddleN + " " + textBoxLastN;
labelOutput.Text = output;
You have to include .Text for all textboxes so it should look like this
string output;
output = textBoxPrefT.Text + ". " + textBoxFirstN.Text + " " + textBoxMiddleN.Text + " " + textBoxLastN.Text;
labelOutput.Text = output;

How do i place quotes around a variable before passing it to Crystal Reports

I have a routine where i prompt the user for a value. In this case the city. They will type in for example LA. I store this value in a variable named inputValue.
Now i need to pass a string to crystal reports that uses this input and i want it to look like this
{member.name} = "LA"
string inputValue = GetInputValue("Enter value for " + fieldName);
string sqlInput = sqlInput.Substring(0, leftPos - 1) + " + inputValue + " + sqlInput.Substring(rightPos + 2);
O thought by using " + inputValue + " would do the trick but it only puts the quotation mark after the input value ex. LA \". What is the proper way to quote this?
" + inputValue + " +
Should be
inputValue +
Thus making
string sqlInput = sqlInput.Substring(0, leftPos - 1) + inputValue +
sqlInput.Substring(rightPos + 2);
Assuming you don't want '"' characters leading and trailing your string.
Then that would be
string sqlInput = sqlInput.Substring(0, leftPos - 1) +"\"" + inputValue + "\"" +
sqlInput.Substring(rightPos + 2);

Why is EO.PDF Timing Out When Converting HTML File to PDF in C#

I have the following bits of code:
public static void WriteHTML(string cFile, List<Movie> mList)
{
int lineID = 0;
string strMovie, strGenre, tmpGenre = null;
// initiates streamwriter for catalog output file
FileStream fs = new FileStream(cFile, FileMode.Create);
StreamWriter catalog = new StreamWriter(fs);
string strHeader = "<style type=\"text/css\">\r\n" + "<!--\r\n" + "tr#odd {\r\n" + " background-color:#e2e2e2;\r\n" + " vertical-align:top;\r\n" + "}\r\n" + "\r\n" + "tr#even {\r\n" + " vertical-align:top;\r\n" + "}\r\n" + "div#title {\r\n" + " font-size:16px;\r\n" + " font-weight:bold;\r\n" + "}\r\n" + "\r\n" + "div#mpaa {\r\n" + " font-size:10px;\r\n" + "}\r\n" + "\r\n" + "div#genre {\r\n" + " font-size:12px;\r\n" + " font-style:italic;\r\n" + "}\r\n" + "\r\n" + "div#plot {\r\n" + " height: 63px;\r\n" + " font-size:12px;\r\n" + " overflow:hidden;\r\n" + "}\r\n" + "-->\r\n" + "</style>\r\n" + "\r\n" + "<html>\r\n" + " <body>\r\n" + " <table>\r\n";
catalog.WriteLine(strHeader);
foreach (Movie m in mList)
{
strMovie = lineID == 0 ? " <tr id=\"odd\" style=\"page-break-inside:avoid\">" : " <tr id=\"even\" style=\"page-break-inside:avoid\">";
catalog.WriteLine(strMovie);
foreach (string genre in m.Genres)
tmpGenre += ", " + genre;
try
{ strGenre = tmpGenre.Substring(2); }
catch (Exception)
{ strGenre = null; }
strMovie = " <td>\r\n" + " <img src=\".\\images\\" + m.ImageFile + "\" width=\"75\" height=\"110\">\r\n" + " </td>\r\n" + " <td>\r\n" + " <div id=\"title\">" + m.Title + "</div>\r\n" + " <div id=\"mpaa\">" + m.Certification + " " + m.MPAA + "</div>\r\n" + " <div id=\"genre\">" + strGenre + "</div>\r\n" + " <div id=\"plot\">" + m.Plot + "</div>\r\n" + " </td>\r\n" + " </tr>\r\n";
catalog.WriteLine(strMovie);
lineID = lineID == 0 ? 1 : 0;
}
catalog.WriteLine(" </table>\r\n" + " </body>\r\n" + "</html>");
catalog.Close();
}
public static void WritePDF(string cFile, string pdfFile)
{
// Sets up PDF to write to
EO.Pdf.HtmlToPdf.Options.PageSize = new SizeF(8.5f, 11f);
EO.Pdf.HtmlToPdf.Options.OutputArea = new RectangleF(0.5f, .25f, 7.5f, 10.25f);
HtmlToPdf.ConvertUrl(cFile, pdfFile);
}
My HTML file writes fine, but when it tried to convert the HTML file to PDF I get an exception that it times out.
I did a test previously, and had it convert the code (not the file) within the WriteHTML function and it worked great. I have confirmed that the cFile exists and is a valid file (created previously in WriteHTML). The path to pdfFile is valid, and the documentation does not state the file needs to already exist (.ConvertHTML did not need an existing file).
Only thing I can think of is that the catalog.html file isn't released and ready to read yet. I made sure I closed it in the WriteHTML function. How can I test that the file is ready to be read?
Tried setting .MaxLoadWaitTime = 120000 with no luck.
Any clues would be greatly appreciated!
After a battery of further testing, and scouring the EO support forums, it appears to be a limitation of the free version of EO. It seems to have difficulty with HTML files over 3MB.
It's a shame since the EO product is very good, but not unfortunately not worth $250 IMO.

Categories

Resources