Image1.Visible = true;
Label2.Text = "Correct Ans = " + answer.ToString();
Label3.Text = "Incorrect Ans = " + wrong.ToString();
Label20.Text = "Total Questions = " + count.ToString();
Label21.Text = "Score = " + answer* 10;
Label26.Text = "Percentage = " + Math.Round(answer / count* 100)+ " %";
answer = 0;
wrong = 0;
There are many different ways to achieve this.I would suggest you read A Beginner's Tutorial on ASP.NET State Management and decide which one suits you best
Here's a simple example which uses three of these technologies, namely:
Query strings
Session state
Cookies
Setting values:
string name = txtName.Text;
//1.Session
Session["name"] = name;
//2.Cookies
Response.Cookies["name"].Value = name;
Response.Cookies["name"].Expires = DateTime.Now.AddDays(1);
//3.Query strings
Response.Redirect("Page2.aspx?name=" + name);
Reading values:
//1.Session
string nameFromSession = Session["name"] as string;
//2.Cookies
string nameFromCookie = Request.Cookies["name"].Value;
//3.Query strings
string nameFromQueryString = Request.QueryString["name"];
Related
I have my aspx pages , and some logic is written in code behind to bind the data of aspx pages.Now using wkhtmltopdf i am sending these files to convert into pdf files.Its work very well when the data is smaller in size however when the data comes in larger side for that page the wkhtmltopdf stops working and doesnt create any pdf file.
Can you suggest any way to overcome this problem. What i tried was limiting the data.. for example i have repeater control on my page if that controls binds 350 record i am only taking 20 records , but also if size of those 20 records are large it happens the same
the also next option i tried is my giving the parameter inside
Process myProcess = Process.Start(startInfo);
myProcess.WaitForExit(few seconds);
but it still doesnt work
Please suggest
Process myProcess = Process.Start(startInfo);
string error = myProcess.StandardError.ReadToEnd();
myProcess.WaitForExit();
myProcess.Close();
objZip.AddFile(destinationFile, "Files");
myProcess.Dispose();
myProcess = null;
This is the answer => what happen is when u start process , and wait for exit () both creates a deadlock somtimes which hammers the performance .. by adding readtoend() method before waitforexit() clears the deadlock and then continues further processing ...
this solves my problem.
The reason i am showing complete solution is that , wkhtmltopdf is very good for creating dynamic pdf files , but this is free tool as well and hence very limited documentation for this ..
private void ProcessHtmlToPdf(List<ExportToPdfCategories> lstExportToPdfCategories)
{
try
{
string pdfExportPath = string.Empty;
string PDFdeletePath = string.Empty;
string deletePath = string.Empty;
string PdfSavePath = string.Empty;
if (lstExportToPdfCategories != null)
{
foreach (var item in lstExportToPdfCategories)
{
path = "";
pdfExportPath = profile + ApConfig.CurrentCompany.CompId + "/" + objExpDetails.AddedForId.ToString() + "/" + item.HeaderCategory;
PDFdeletePath = profile + ApConfig.CurrentCompany.CompId + "/" + objExpDetails.AddedForId.ToString();
PdfSavePath = profile + ApConfig.CurrentCompany.CompId + "/" + objExpDetails.AddedForId.ToString() + "/" + item.HeaderCategory;
htmlpath = profile + ApConfig.CurrentCompany.CompId + "/" + objExpDetails.AddedForId.ToString() + "/" + item.HeaderCategory;
deletePath = Server.MapPath(PDFdeletePath);
string ClearDirectory = Server.MapPath(PdfSavePath);
if (Directory.Exists(deletePath))
{
//Directory.Delete(ClearDirectory, true);
//Directory.Delete(deletePath, true);
}
if (!Directory.Exists(Server.MapPath(pdfExportPath)))
{
Directory.CreateDirectory(Server.MapPath(pdfExportPath));
}
string name =
pdfExportPath = pdfExportPath + "/" + objExpDetails.FirstName + "." + objExpDetails.LastName + "-" + item.HeaderCategory + "_" + (drpYear.SelectedValue != "0" ? Convert.ToString(drpYear.SelectedValue) : System.DateTime.Now.Year.ToString()) + ".pdf";
objpath = Server.MapPath(pdfExportPath);
//this will create html mockup
//item.WebsiteUrl = CreateTemportHtmlFile(item.HeaderCategory, PdfSavePath, item.WebsiteUrl);
if (path == "")
{
path = CreateTemportHtmlFile(PdfSavePath, item.HeaderCategory);
}
HtmlToPdf(item.WebsiteUrl, objpath, path);
}
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + objExpDetails.FirstName + "." + objExpDetails.LastName + "-actusdocs.zip");
Response.ContentType = "application/zip";
objZip.Save(Response.OutputStream);
Response.End();
}
}
catch (Exception ex)
{
//SendEmail.SendErrorMail("ProcessHtmlToPdf method : ", ex.Message + ex.StackTrace, objExpDetails);
}
}
//Method overloading
//this is for testing html pages(not in used during main running)
private string CreateTemportHtmlFile(string categoryName, string htmlMockupSavingPath, string websiteURL)
{
try
{
string sessionId = Session.SessionID;
int employeeId = Convert.ToInt32(hdnEmployeeId.Value);
htmlMockupSavingPath = Server.MapPath(htmlMockupSavingPath) + "\\" + categoryName + ".html";
StreamWriter sw;
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(websiteURL);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sw = File.CreateText(htmlMockupSavingPath);
sw.WriteLine(result);
sw.Close();
Response.WriteFile(htmlMockupSavingPath);
}
catch (Exception ex)
{
SendEmail.SendErrorMail("CreateTemportHtmlFile method : ", ex.Message + ex.StackTrace, objExpDetails);
}
return htmlMockupSavingPath;
}
private string CreateTemportHtmlFile(string PdfSavePath, string categoryName)
{
try
{
string sessionId = Session.SessionID;
int employeeId = Convert.ToInt32(hdnEmployeeId.Value);
PdfSavePath = Server.MapPath(PdfSavePath) + "\\BindHeader.html";
htmlpath = htmlpath.Substring(1);
htmlpath = ConfigurationManager.AppSettings["pdfUrlPath"].ToString() + htmlpath + "/BindHeader.html";
string exportedYear = (drpYear.SelectedValue == "0" ? System.DateTime.Now.Year.ToString() : drpYear.SelectedValue);
StreamWriter sw;
if (categoryName == "MidYearAppraisal" || categoryName == "EndYearAppraisal")
{
myRequest = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["pdfUrlPath"] + "/User/UserPdfReports/UserPdfHeaderforAppraisal.aspx?session=" + sessionId + "&empId=" + employeeId + "&catName=" + categoryName + "&expYear=" + exportedYear);
}
else
{
myRequest = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["pdfUrlPath"] + "/User/UserPdfReports/UserPdfHeader.aspx?session=" + sessionId + "&empId=" + employeeId + "&catName=" + categoryName + "&expYear=" + exportedYear);
}
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sw = File.CreateText(PdfSavePath);
sw.WriteLine(result);
sw.Close();
Response.WriteFile(PdfSavePath);
}
catch (Exception ex)
{
SendEmail.SendErrorMail("CreateTemportHtmlFile method : ", ex.Message + ex.StackTrace, objExpDetails);
}
return htmlpath;
}
private void HtmlToPdf(string website, string destinationFile, string path)
{
try
{
string hrmlPath = ConfigurationManager.AppSettings["pdfUrlPath"].ToString() + "/user/UserPdfReports/FooterPdfReports.html";
ProcessStartInfo startInfo = new ProcessStartInfo();
string switches = "";
switches += "--header-html " + path + " --footer-html " + hrmlPath;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
startInfo.FileName = "C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe";
startInfo.Arguments = switches + " " + website + " " + destinationFile;
Process myProcess = Process.Start(startInfo);
string error = myProcess.StandardError.ReadToEnd();
myProcess.WaitForExit();
myProcess.Close();
objZip.AddFile(destinationFile, "Files");
myProcess.Dispose();
myProcess = null;
}
catch (Exception ex)
{
//SendEmail.SendErrorMail("HtmlToPdf : ", ex.Message + ex.StackTrace, objExpDetails);
}
}
I'm trying to research the routed direction using google maps for asp.net control. Here is my Code.
GoogleMapForASPNet1.GoogleMapObject.APIKey = ConfigurationManager.AppSettings["GoogleAPIKey"];
GoogleMapForASPNet1.GoogleMapObject.Width = "1100px";
GoogleMapForASPNet1.GoogleMapObject.Height = "600px";
GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 10;
GoogleMapForASPNet1.GoogleMapObject.CenterPoint = new GooglePoint("1", 1.352083, 103.819836);
GoogleMapForASPNet1.GoogleMapObject.ShowTraffic = true;
int count=0;
bool flag = false;
GoogleMapForASPNet1.GoogleMapObject.Points.Clear();
foreach (var gitem in tblG)
{
foreach (var item in tblDT)
{
if (item.Latitude==gitem.Latitude && item.Longitude==gitem.Longitude && flag!=true)
{
count += 1;
GooglePoint GP1 = new GooglePoint();
GP1.ID = "GP" + count.ToString();
GP1.Latitude = Convert.ToDouble(gitem.Latitude);//latitude;
GP1.Longitude = Convert.ToDouble(gitem.Longitude);
GP1.InfoHTML = " Name:<b>" + Name + "</b></br>Point:<b>" + "GP" + count.ToString() + "</b></br>Time:<b>" + gitem.CDate.ToString() + "</b></br>";//stime;
GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP1);
string address = gitem.Latitude + "," + gitem.Longitude;
GoogleMapForASPNet1.GoogleMapObject.Directions.Addresses.Add(address);
flag = true;
}
}
flag = false;
}
I want it as Routed Direction is only between start and End point.
But I got result look like driving Direction. I don't want to get that result. How to fix that problem?
The .Text on add is giving the error, I believe I have the right assemblies in place.
StringCollection sc = new StringCollection();
for (int i = 1; i <= 2; i++)
{
//extract the TextBox values
string txt1 = ((TextBox)Page.FindControl("TextBox1" + i.ToString())).Text;
string txt2 = ((TextBox)Page.FindControl("TextBox2" + i.ToString())).Text;
string txt3 = ((TextBox)Page.FindControl("TextBox3" + i.ToString())).Text;
string txt4 = ((TextBox)Page.FindControl("TextBox4" + i.ToString())).Text;
string txt5 = ((TextBox)Page.FindControl("TextBox5" + i.ToString())).Text;
string txt6 = ((TextBox)Page.FindControl("TextBox6" + i.ToString())).Text;
string txt7 = ((TextBox)Page.FindControl("TextBox7" + i.ToString())).Text;
string txt8 = ((TextBox)Page.FindControl("TextBox8" + i.ToString())).Text;
string txt9 = ((TextBox)Page.FindControl("TextBox9" + i.ToString())).Text;
sc.Add(txt1.Text, txt2.Text, txt3.Text, txt4.Text, txt5.Text, txt6.Text, txt7.Text, txt8.Text, txt9.Text);
}
InsertRecords(sc);
You are basically calling string.Text since the type of txt1, txt2, etc is string, hence the error. But note that you are already calling .Text on the TextField control so what you probably intend to do is:
sc.AddRange(new string[]{txt1, txt2, txt3, ...});
The path of video(extension.wmv,.avi) is stored in SQL Server. And I have to create thumbnail and dispaly it on ASPX page.
Please share its code, if any body know this.
Thanks in Advance
For AVI you can use the below codeproject
http://www.codeproject.com/Articles/7388/A-Simple-C-Wrapper-for-the-AviFile-Library
For others try
http://sourceforge.net/projects/directshownet/
http://code.google.com/p/slimdx/
I have some bit of code for generating thumbnail video.
for that you need to have third party exe named "ffmpeg.exe" which is available for free. you can download from here
Now i have create function below which generate thumbnail video from original video.
you can change variable according to your requirement.
private bool SaveVideo(FileUpload fupload)
{
string VideoResolutionWidth = "400" ; //define video res. width
string VideoResolutionHeight = "280"; //define video res. height
string VideoThumbWidth = "100";//define jpg res. width
string VideoThumbHeight = "100"; //define jpg res. height
string VideoLocation = HttpContext.Current.Server.MapPath("~/ConverterFolder/Video/");
string ConverterPath = HttpContext.Current.Server.MapPath("~/ConverterFolder/");
String LargeFileName = "TestVideo.wmv"; // Thumb Video file name
string ThumbFileName= "Testvideo.jpg";
// Save Original video file first
if (fupload.PostedFile.FileName != "")
{
fupload.PostedFile.SaveAs(ConverterPath + "\\" + System.IO.Path.GetFileName(fupload.PostedFile.FileName.Replace(" ", "_")));
}
if (System.IO.File.Exists(ConverterPath + "\\" + System.IO.Path.GetFileName(fupload.PostedFile.FileName.Replace(" ", "_"))))
{
string inipath = ConverterPath;
string flvCMD, flvArg;
string a_res_width, a_res_height, a_audioRate, a_frameRate, i_res_width, i_res_height;
a_res_width = VideoResolutionWidth;
a_res_height = VideoResolutionHeight;
i_res_width = VideoThumbWidth;
i_res_height = VideoThumbHeight;
a_audioRate = "22050";
a_frameRate = "15";
string VideoThumbResolution = i_res_width + "x" + i_res_height;
string VideoResolution = a_res_width + "x" + a_res_height;
String videoPATH = VideoLocation + "\\" + LargeFileName.Replace(" ", "_");
flvCMD = ConverterPath + "ffmpeg.exe";
flvArg = "-i " + ConverterPath + "\\" + System.IO.Path.GetFileName(fupload.PostedFile.FileName.Replace(" ", "_")) + " -s " + VideoResolution + " -r " + a_frameRate + " -b 7500000 -ar " + a_audioRate + " -ab 48 " + videoPATH;
try
{
Process process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = flvCMD;
process.StartInfo.Arguments = flvArg;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.Close();
process.Dispose();
if (System.IO.File.Exists(videoPATH))
{
Process process1 = new Process();
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.RedirectStandardOutput = true;
process1.StartInfo.RedirectStandardError = true;
process1.StartInfo.CreateNoWindow = true;
process1.StartInfo.FileName = flvCMD;
process1.StartInfo.Arguments = "-i " + ConverterPath + "\\" + System.IO.Path.GetFileName(fupload.PostedFile.FileName.Replace(" ", "_")) + " -an -ss 00:00:01 -r 1 -vframes 1 -s " + VideoThumbResolution + " -f mjpeg -y " + VideoLocation "\\" + ThumbFileName;
process1.Start();
string outputMeta1 = process1.StandardOutput.ReadToEnd();
process1.Close();
process1.Dispose();
}
else
{
return false;
}
}
catch (Exception)
{
}
}
return true;
}
Hope this will help you. happy coding....
Why does this work:
ListItem item = new ListItem();
string value = lstAvailExtPropsToFilter.SelectedItem.Text +" = "+ txtExtPropToFilter.Text;
string text = lstAvailExtPropsToFilter.SelectedItem.Text + " = " + txtExtPropToFilter.Text;
item.Text = text;
item.Value = value;
lstExtPropsToFilter.Items.Add(item);
But not this:
ListItem item = new ListItem();
string value = string.Format("<key>{0}</key><value>{1}</value>", lstAvailExtPropsToFilter.SelectedItem.Text, txtExtPropToFilter.Text);
string text = lstAvailExtPropsToFilter.SelectedItem.Text + " = " + txtExtPropToFilter.Text;
item.Text = text;
item.Value = value;
lstExtPropsToFilter.Items.Add(item);
You would have to escape the string so it works in HTML. Try Server.HTMLEncode.
Server.HTMLEncode("<key>{0}</key><value>{1}</value>")
Then when you need to pull the value you, use Server.HTMLDecode.