Saturday, September 22, 2012

Stable DIV while asynchronous postback in ASP.NET








Div Scoll during page postback.


Hello Guys,

If you have any div tag inside update panel, it got displaced during postback of page on checkbox index change or dropdown index change. I had struggled a lot for this issue.

I Found very simple one line solution for this issue

just add below line in div CSS

.DivCSS
{
position: absolute; 
}

Drop all stored procedure from a database



-- Using below script you can drop all stored procedure from selected database
 


declare @procName varchar(500)
declare cur cursor

for select [name] from sys.objects where type = 'p'
open cur
fetch next from cur into @procName
   while @@fetch_status = 0
     begin
       exec('drop procedure ' + @procName)
       fetch next from cur into @procName
    end
close cur
deallocate cur

Club Multiple Powerpoint to Single File in ASP.NET


C#.NET : Merge multiple PPT into one file



 protected void btnClubPPT_Click(object sender, EventArgs e)
        {
            try
            {
                    String strPath = Server.MapPath("Uploads\\");
                    String strConsolidatedPPT = Server.MapPath("SuccessStory\\");
                    string[] files = Directory.GetFiles(strPath, "*.ppt");
                    for (int i = 0; i < files.Length; i++)
                    {
                        CopySlidesFromPPT(files[i].ToString(), strConsolidatedPPT + "Consolidated Success Story.ppt");
                    }
                }
                System.Diagnostics.Process.Start(Server.MapPath("SuccessStory\\") + "Consolidated Success Story.ppt");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                GC.Collect();
            }



 public static bool CopySlidesFromPPT(string sourcefile, string dstfile)
        {
            bool success = false;

            // Create a link to the PowerPoint object model           

            Microsoft.Office.Interop.PowerPoint.Application oPowerPoint = new Microsoft.Office.Interop.PowerPoint.Application ();
            Microsoft.Office.Interop.PowerPoint.Presentations oPres = oPowerPoint.Presentations;
            Microsoft.Office.Interop.PowerPoint.Presentation oPre = null;

            // If the destination presentation exists on disk, load it so
            // that we can append the new slides           

            if (File.Exists(dstfile) == true)
            {
                try
                {
                    // Try and open the destination presentation
                    oPre = oPres.Open(dstfile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                }
                catch
                {
                    oPre = null;
                }
            }
            else
            {
                // Create a new presentation
                try
                {
                    oPre = oPres.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
                }
                catch
                {
                    oPre = null;
                }
            }

            // Do we have a master presentation ?          

            if (oPre != null)
            {
                // Point to the slides in the master presentation
                Microsoft.Office.Interop.PowerPoint.Slides oSlides = oPre.Slides;
                try
                {
                    try
                    {
                        // Open the source presentation
                        Microsoft.Office.Interop.PowerPoint.Presentation ppps = oPres.Open(sourcefile, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
                        try
                        {
                            // Insert the source slides onto the end of the merge presentation
                            oSlides.InsertFromFile(sourcefile, oSlides.Count, 1, ppps.Slides.Count);
                            oPre.SaveAs(dstfile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoFalse);
                            // Save the merged presentation back to disk
                            // oPre.SaveAs(dstfile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoFalse);
                            // Signal success
                            success = true;
                        }
                        finally
                        {
                            // Close the source presentation
                            ppps.Close();
                        }
                    }
                    catch
                    {

                    }

                }
                finally
                {
                    // Ensure the merge presentation is closed
                    oPre.Close();
                    // Release the COM object holding the merged presentation
                    Marshal.ReleaseComObject(oPre);
                    oPre = null;
                    // Release the COM object holding the presentations
                    Marshal.ReleaseComObject(oPres);
                    oPres = null;
                    // Release the COM object holding the powerpoint application
                    Marshal.ReleaseComObject(oPowerPoint);
                    oPowerPoint = null;
                }
            }
            return success;
        }

How to Open Powerpoint file on button click in ASP.NET



You can open any power point by its location on click of a button

protected void btnClubPPT_Click(object sender, EventArgs e)
        {
            try
            {
                   System.Diagnostics.Process.Start("You PPT.ppt");
             }

            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                GC.Collect();
            }

Managing Session Integrity in .NET Core Web Applications: A Middleware Approach

 In our journey of developing a .NET Core web application, we encountered a peculiar challenge with our time-tracking feature. The applicati...