LIKE US ON FACE BOOK

Thursday, 24 August 2017

Auto restore Nuget packages with TFS Build (Useful for non Visual studio environment like test server)

Procedure to enable automatic nuget restore in VS 2015/2017

> Create a folder with name ".nuget" in the solution root

> Add these 3 files in to ".nuget folder"
1. "nuget.config"
2. "NuGet.exe"
3. "NuGet.targets"

> Add these tag in you all project file by using node pad or by VS(unload project to edit)

1. <NuGetPackageImportStamp></NuGetPackageImportStamp>
    <RestorePackages>true</RestorePackages>

Add this entry inside "<PropertyGroup>" tag.

2. <Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

Add this in "<project>" tag & would be good if these all enties added in ending of tag.

> This step is addtional but recomemded sometimes.
Add a file with named "repositories.config" inside packages folder & refer all libraries "packages.config". if libraries dont have "packages.config", then no need to refer those.

eg:- <?xml version="1.0" encoding="utf-8"?>
<repositories>
  <repository path="..\Myportal\packages.config" />
  <repository path="..\Myportal.UnitTests\packages.config" />
  <repository path="..\\Myportal.Core\packages.config" />
</repositories>

Here "Myportal" is example taken to represnt library.

Monday, 5 June 2017

Creating Context menu Extension for Project wise i.e. (Adding right lick option for project selected) for Visual Studio 2013 & above

> Create a VSIX project
> Add Custom Commad to project(available in extensibility)
> Use "IDM_VS_CTXT_PROJNODE" as ID for parent, as it is most important to specify that its project node.

eg:-

<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_PROJNODE"/>

this is avalaible in <groups>

> handle the action as you want in "call back function" in ".cs file".

and here is some more option if you wanna have,

> Adding a Button to the Solution Explorer Toolbar
use ID as "IDM_VS_TOOL_PROJWIN" as parent id.

Wednesday, 15 July 2015

Display or Return any File from MVC Action and display in Bootstrap Modal

Hi Guys,

Here is simplest way to return file from MVC action and display in View or Boot Strap Modal .

View :-
<button id="testbutton" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#dummyModal">Open Modal</button>

<div class="modal fade" id="dummyModal" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h2 class="modal-title">Patient consent File</h2>
                </div>
                <div class="modal-body">
                    <div ></div>
                    <iframe id="dummyContent" style="width:100%; height: 700px; border:0px;"></iframe>
                    <div id="dummyMessage" style="display:none;" class='alert alert-info'>File not found!<br></div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>

Jquery :-

 $(document).on("click", "#testbutton", function () {
            var url = '/Patient/GetPatientConsentFile?id=49'
            $('#dummyContent').attr('src', url);
    });

Controller:-

 public ActionResult GetPatientConsentFile(string id)
        {
            int ID = 0;
            int.TryParse(id, out ID);
//if you data in string , then convert it to byte[]
            var contents = System.IO.File.ReadAllBytes("file path");
//if you dont have file path then pass global content type ie "System.Net.Mime.MediaTypeNames.Application.Octet" or pass specific MIME type, (please go through mime type in google)
            string contentType = MimeMapping.GetMimeMapping("filepath");
            return File(contents, contentType);
        }

this works like a charm, please do let me know if you have any concerns.

Tuesday, 14 July 2015

Convert XML to relavent HTML and apply XSLT style sheet as well & display contents in Bootstrap Modal in MVC Using AJAX

Hi Guys ,

Here is the way to convert XML data to corresponsing HTML by apply XSLT style sheet & display contents in Bootstrap Modal.

Bootstrap Modal:

<div class="modal fade" id="ccdaModel" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button"  return false;" class="close" data-dismiss="modal">&times;</button>
                    <h2 class="modal-title">Hi Test Modal </h2>
                </div>
                <div class="modal-body">
                        <div id="ccdaContent"></div>
                        <div id="ccdaMessage" style="display:none;" class='alert alert-info'>File not found!<br></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" return false;" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>

        </div>

JS Code:-
$(document).on("click", ".cutomCCDA", function () {
            $.ajax({
                type: "GET",
                url: url,
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                success: function (result) {
                    $('#ccdaContent').html(result);
                },
                error: function (xhr, status) {
                    console.log(status);
                }
            });
    });

Action Method:-

public ActionResult ConvertXMLtoHTMLwithXSLT()
        {
            string xmldocument= "xml string";
            string XSLTfile= @"give path here";
            if (!string.IsNullOrEmpty(xmldocument))
            {
                    //load XSLT
apply xslt setting according to your needs
                    XsltSettings xslsettings = new XsltSettings();
                    xslsettings.EnableScript = true;
                    xslsettings.EnableDocumentFunction = true;
//apply xslt
                    XslCompiledTransform proc = new XslCompiledTransform();
                    proc.Load(Server.MapPath(XSLTfile), xslsettings, null);
                    using (StringReader sr = new StringReader(xmldocument))
                    {
                        using (XmlReader xr = XmlReader.Create(sr))
                        {
                            using (StringWriter sw = new StringWriter())
                            {
//apply xsl to out XML
                                proc.Transform(xr, null, sw);
                                return Content(sw.ToString());
                            }
                        }
                    }
            }
            return Content("<div class='alert alert-info'>File not found!<br></div>");
        }

Hope it helps you..please do let meknow if you have any concerns..

Wednesday, 8 July 2015

Trigger Bootstrap Model on PageLoad automatically

Hi Guys ,

Here is way if you wanna load Bootstrap Model by default on page load,
here is a way.

//Boot strap model HTML
<div class="modal fade bs-example-modal-lg" id="PatientConsent" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Patient Consent</h4>
            </div>
            <div class="modal-body">
                <p>Hi am dummy model</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
            </div>
        </div>
    </div>
</div>

// JS code to trigger model on PageLoad
$(document).ready(function(){
//trigger model on page load
    $('#myModal').modal('show');
});

Hope this helps you

Uploading Files using Ajax in MVC4 using Form object.

Hi Guys ,

If you are looking for a way to upload files in AJAX for in  MVC .
here is simple way, which works like charm :)

please comment if you like it..

//HTML for file upload control
<input type="file" name="myfile" id="pcfile" />


//JS code to access files uploaded and making AJAX call

$(document).on("click", "#btnSubmit", function () {
//here am reading file data from my file upload control
            var file = $('#pcfile').data('ace_input_files');
            if (file.length > 0) {
//check if formdata exists
                if (window.FormData != undefined) {
//create a form object to add files in to form object
                    var fileData = new FormData();
                    for (var i = 0; i < file.length; i++) {
                        fileData.append("file" + i, file[i]);
                        $.ajax({
                            type: "POST",
                            url: '/ControllerName/ActionName' + "?patientID=" + patientID,
                            contentType: false,
                            processData: false,
                            data: fileData,
                            success: function (result) {
                               //success logic
                            },
                            error: function (xhr, status) {
                                console.log(status);
                            }
                        });
                    }
                }
            }
        }
    });

// Action method to read file from HTTP request context object, posting in form object
 [HttpPost]
        public void Uploadfiles(string patientID)
        {
            if (!string.IsNullOrEmpty(patientID))
            {

                //save the uploaded file in path specified in app settings entry
                string fileName = string.Empty;
                String path = string.Empty;
                int pID = 0;
                foreach (string file in Request.Files)
                {
                    var fileContent = Request.Files[file];
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        Stream stream = fileContent.InputStream;
                        fileName = User.FirstName + User.LastName + Regex.Replace(DateTime.Now.ToString(), "[^a-zA-Z0-9_]+", "_") + Path.GetExtension(fileContent.FileName);
                        string PatientConsentDirectory = System.Configuration.ConfigurationManager.AppSettings["PatientConsentFilePath"];
                        if (!string.IsNullOrEmpty(PatientConsentDirectory))
                        {
                            bool folderExists = Directory.Exists(Server.MapPath(PatientConsentDirectory));
                            if (!folderExists)
                            {
                                Directory.CreateDirectory(Server.MapPath(PatientConsentDirectory));
                            }
                            path = Path.Combine(Server.MapPath(PatientConsentDirectory), fileName);
                            fileContent.SaveAs(path);
                            stream.Close();
                        }
                    }
                }
            }
        }

Hope this help you, please comment if it helped or if you have any concerns

Wednesday, 24 April 2013

Adding Custom Error Page to Asp.net Project

Hi Friends,

Please do follow these steps for Adding Custom Error Page.

>
     Create a error Page for eg:- error.aspx

>
     add entry to app setting ,if you have
     like this  
          
    <add key="Errorpage" value="/errorpage.aspx"/>

>  add entry to appsecurity,if you have 
    ike this 

   <page name ="error page" url="/projectname/errorpage.aspx">

      define any access rule or httpget or httpost 

  </page> 

>
   Main thing is make entry in web.config as below
  
  <configuaration> 
         <system.web>  
                       <customerrors mode="On" defaultRedirect="/error.aspx"/>
        </system.web>
  </configuaration>
   
Any doubts please do ask.