Monday, 11 December 2017

Create AJAX Modal

On the page:

<style>
  .modalPopup
  {
    background-color: #FFFFFF;
    border-width: 3px;
    border-style: solid;
    border-color: black;
    padding-top: 10px;
    padding-left: 10px;
    padding-right: 10px;
    min-width: 300px;
    min-height: 120px;
  }
</style> 

<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<cc1:ModalPopupExtender 
    ID="ModalPopupExtender1" 
    BehaviorID="mpe" 
    runat="server"
PopupControlID="pnlPopup" 
    TargetControlID="lnkDummy" 
    BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>

<asp:Panel 
    ID="pnlPopup" 
    runat="server" 
    CssClass="modalPopup" 
    Style="display: none; 
    overflow:auto; 
    max-height: 600px;">
  <div>
    <b runat="server" 
       id="modalHeader" 
       style="font-weight:600; 
       font-size:18px;">
    </b>
  </div>

  <hr />

  <div>
<div runat="server" 
       id="modalContent" 
       style="font-size: 14px"> 
    </div>

    <br /> <br />
    <asp:Button ID="btnHide" 
            runat="server" 
            Text="OK" 
            OnClientClick="return HideModalPopup()" />

    <br /> <br />
  </div>
</asp:Panel>

<script type="text/javascript">
  function ShowModalPopup() {
$find("mpe").show();
return false;
}
function HideModalPopup() {
$find("mpe").hide();
return false;
}
</script>



Call from code behind:

public void DisplayMessage(string header, string body)
{
modalHeader.InnerHtml = header;
modalContent.InnerHtml = body;
  ModalPopupExtender1.Show();
}

Sunday, 10 December 2017

Windows 10 Disable Delay Time in Launching Startup Programs

Windows 10 delays on load and startup for few second. To resolve this issue:

  1. Open Windows Registry Editor: Windows + R > regedit
  2. Navigate to: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer
  3. Under Explorer key, create a new key and set its name as Serialize
  4. Select Serialize key and in right-side pane, create a new DWORD StartupDelayInMSecand set its value to 0 to disable startup delay time:
  5. Close Registry Editor and restart your computer to take effects.


Wednesday, 29 November 2017

Browse UNC path using Windows CMD


  • PUSHD <UNC PATH> will create a temporary virtual drive and get into it
  • POPD will delete the temporary drive and get you back to the path you were when you entered pushd


Thursday, 16 November 2017

Convert HTML to Docx and Pdf using Microsoft.Office.Interop.Word

// use _Application and _Document instead of var to avoid ambiguities 
_Application word = new Application();
_Document document = word.Documents.Open(FileName: @"C:\index.html", ConfirmConversions: false, ReadOnly: false);

word.Visible = false;

// impersonated user must have read-write access to the following locations

var pdfOutputFile = @"C:\Temp\document.pdf";
var docOutputFile = @"C:\Temp\document.docx";

byte[] Content = null;

.
.
.
case "pdf":
document.SaveAs2(FileName: pdfOutputFile, FileFormat: WdSaveFormat.wdFormatPDF);
document.Close();
word.Quit();
Content = File.ReadAllBytes(pdfOutputFile);
break;

case "docx":

foreach (InlineShape image in document.InlineShapes)
{
// make sure images are embeded
if (image.LinkFormat != null)
{
try
{
image.LinkFormat.SavePictureWithDocument = true;
image.LinkFormat.BreakLink();
}
catch { /* do nothing */ }
}
}
document.SaveAs2(FileName: docOutputFile, FileFormat: WdSaveFormat.wdFormatDocumentDefault);
document.Close();
word.Quit();
Content = File.ReadAllBytes(docOutputFile);
break;
.
.
.

// download file as byte[]
if (Content != null)
{
Response.AddHeader("content-disposition", "attachment; filename=" + (pdfOutputFile or docOutputFile));
Response.BufferOutput = true;
Response.OutputStream.Write(Content, 0, Content.Length);
Response.End();
}


Important notes: 


  1. In order to be able to save document, create a new "Desktop" directory inside of "C:\Windows\SysWOW64\config\systemprofile\"
  2. The library will not work on Server 2016 with O365 or Office 2016. On server 2016, need to use Office 2013.



Tuesday, 31 October 2017

MS-SQL: Strip NON-Alphabetic Characters From String

Create Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin

    Declare @KeepValues as varchar(50)
    Set @KeepValues = '%[^a-z]%'
    While PatIndex(@KeepValues, @Temp) > 0
        Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')

    Return @Temp
End

TEST:
Select dbo.RemoveNonAlphaCharacters('abc1234def5678ghi90jkl')


Analysis Service in Power BI Report Server

 We couldn’t connect to the Analysis Services server. Make sure you’ve entered the connection string correctly... link