Monday, February 28, 2011

Cannot remove an entity that has not been attached.

You will not be able to use attach on a context other then the original context the item was received on unless the entity has been serialized.


public bool deleteslabrecord(TSummeryReport deletetsr)
{
EntityManager.TSummeryReports.DeleteOnSubmit(EntityManager.TSummeryReports.Single(theItem=>theItem==deletetsr));
return SaveChanges();
} 

Wednesday, February 23, 2011

Merge dynamically create PDF at runtime

I played with this more than 3 days. Finally got the solution.


protected void Button1_Click(object sender, EventArgs e)
{
 Guid uniqueid = Guid.NewGuid();
 string uniqueidStr = uniqueid.ToString();
 int cnt = 0;
 string file = Server.MapPath("~/Admin/doc/invoice/Invoice.pdf");
 string masterPDfFile = Server.MapPath("~/Admin/doc/invoice/result.pdf");
 PdfCopyFields myPdfCopy = new PdfCopyFields(new FileStream(masterPDfFile, FileMode.Create));

while (cnt < 3)
{
PdfReader tmpReader = new PdfReader(file);
string tmpFilePath = Server.MapPath("~/Admin/doc/invoice/" +uniqueidStr+ cnt.ToString() + ".pdf");
FileStream tmppoutputFile = new FileStream(tmpFilePath, FileMode.Create);
PdfStamper tmpoutStamper = new PdfStamper(tmpReader, tmppoutputFile);
AcroFields testform = tmpoutStamper.AcroFields;
testform.SetField("T1","Lasantha");
tmpoutStamper.Close();
PdfReader nwpgReader = new PdfReader(tmpFilePath);
PdfTemplate page = tmpoutStamper.GetImportedPage(nwpgReader, 1);
myPdfCopy.AddDocument(nwpgReader);
cnt += 1;
}

myPdfCopy.Close();
cnt = 0;

while (cnt < 3)
{
string tmpFilePath = Server.MapPath("~/Admin/doc/invoice/" + uniqueidStr+cnt.ToString() + ".pdf");
System.IO.File.Delete(tmpFilePath);
cnt += 1;
}

 PdfReader reader = new PdfReader(masterPDfFile);
string resultpath = Server.MapPath("~/Admin/doc/CustomerReports/result.pdf");
 FileStream resultstr=new FileStream(resultpath,FileMode.Create);
PdfStamper result = new PdfStamper(reader, resultstr);
result.Close();
reader.Close();
System.IO.File.Delete(masterPDfFile);
} 

Get DataTable From Linq query

Here code example



public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query)
{

if (query == null)
{
 throw new ArgumentNullException("query");
}

 IDbCommand cmd = ctx.GetCommand(query as IQueryable);
 SqlDataAdapter adapter = new SqlDataAdapter();
 adapter.SelectCommand = (SqlCommand)cmd;
 DataTable dt = new DataTable("sd");

try
{
 cmd.Connection.Open();
 adapter.FillSchema(dt, SchemaType.Source);
 adapter.Fill(dt);
}

finally
{
 cmd.Connection.Close();
}

 return dt; 

} 

Split DataTable in to several DataTables

I achieved this requirement from this code snippet.


public DataTable[] getDataTables(DataTable tableToClone, int seperateVal, int val)
{
 DataTable[] tables = new DataTable[val];
 int count = 0;
 int index = 0;

 DataTable copyTable = null;
 foreach (DataRow row in tableToClone.Rows)
 {
 if ((count++ % seperateVal) == 0)
 {
 copyTable = new DataTable();
 copyTable = tableToClone.Clone();

 tables[index] = copyTable;
 index++;
 }

 copyTable.ImportRow(row);
 }
 return tables;
 } 

Monday, February 14, 2011

Invalid length for a Base-64 char array

This error gave me when i try to encrypt the query string. I solved this issue by http://forums.asp.net/t/1222829.aspx.
It worked fine. But now for some query string values it gives same error. The reason is there was a space character in the query string value. Then i replaced space character with "+". Its working now.

64-bit encoding does not work well with spaces in the string for some odd reason.

Sunday, February 6, 2011

UpdatePanelAnimationExtender FadeIn FadeOut problem-page styles issue

not resolved yet

UpdatePanelAnimationExtender FadeIn FadeOut problem-page resize issue

Basically the problem is after animation worked page is not resize properly.what i did is put div tag name it as rightContainer and place the code whithing it what i need to update.Then Set the  AnimationTarget="rightContainer".

Here the Code.

<FadeIn AnimationTarget="rightContainer" minimumOpacity=".6" />
<
FadeOut AnimationTarget="rightContainer" minimumOpacity=".6" />

Wednesday, February 2, 2011

Get visible false asp Lable value from java script


<style>
.lbl{
display:none;
}
</style>

<asp:Lable ID="label1" runat="server" CssClass="lbl"/>
var val=document.getElementById("<%=label1.ClientID%>").innerHTML;
 

How to Create Events Using Microsoft Graph API with Delegated Permissions and MSAL.js

Microsoft Graph API provides powerful capabilities to interact with Microsoft 365 services. In this guide, we’ll explore how to create calen...