Skip to content

View PDF as part of the MVC page

http://stackoverflow.com/questions/6439634/view-pdf-as-part-of-the-page

I am trying to view a PDF document in my MVC web page, but I cant make it to work.

I would like the PDF to be displayed as a part of the other stuff on the page (header, footer etc.). Currently I have a solution where the PDF is shown, but on the entire page.-

Has anybody done this, if yes then how?

——————————————————–

Why don’t you try using iframe like this :

<iframe src="even file stream action url"></iframe>

I suggest to use object tag if it’s possible, use iframe just for testing.

If you want to render PDF as part of the page as you just did

src='<% Html.RenderAction(“GetPDF”); %>’

Then this is your option

If you need complete control over PDF content using CSS or whatsoever, like Google books and so on, then you need tools that help you to convert each requested page of PDF to Plain Text, HTML or even image. tools like PDFsharp. Search Google For Tools

If you want display PDF as part of the page then this is what you have to do

ASPX: src="<%= Url.Action("GetPDF") %>"
Razor: src="@Url.Action("GetPDF")"

And final answer could be

<object data="<%= Url.Action("GetPDF") %>" type="application/pdf" width="300" height="200">
    alt : <a href="data/test.pdf">test.pdf</a>
</object>

And in the case that you want to return PDF as Stream then you need

public FileStreamResult GetPDF()
{
    FileStream fs = new FileStream("c:\\PeterPDF2.pdf", FileMode.Open, FileAccess.Read);
    return File(fs, "application/pdf");
}

Client-Side Validation for the CheckBoxes Inside a GridView

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
   <Columns> 
      <asp:BoundField HeaderText="n" DataField="sno"> 
       <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
      </asp:BoundField>                
       <asp:TemplateField HeaderText="Select">
            <ItemTemplate>
               <asp:CheckBox ID="chkBxSelect" runat="server" />
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        </asp:TemplateField>
     </Columns>
  </asp:GridView>
 <asp:Button ID="btnPost" runat="server" Text="Post" 
             OnClientClick="javascript:return TestCheckBox();"
             OnClick="btnPost_Click" />

javascript code:
<script type="text/javascript">
   var TargetBaseControl = null;
        
   window.onload = function()
   {
      try
      {
         //get target base control.
         TargetBaseControl = 
           document.getElementById('<%= this.GridView1.ClientID %>');
      }
      catch(err)
      {
         TargetBaseControl = null;
      }
   }
        
   function TestCheckBox()
   {              
      if(TargetBaseControl == null) return false;
      
      //get target child control.
      var TargetChildControl = "chkBxSelect";
            
      //get all the control of the type INPUT in the base control.
      var Inputs = TargetBaseControl.getElementsByTagName("input"); 
            
      for(var n = 0; n < Inputs.length; ++n)
         if(Inputs[n].type == 'checkbox' && 
            Inputs[n].id.indexOf(TargetChildControl,0) >= 0 && 
            Inputs[n].checked)
          return true;        
            
      alert('Select at least one checkbox!');
      return false;
   }
</script>

demo

How to get list of all domain controllers in C#

How to get list of all domain controllers in C#

List all computers in active directory

If you have a very big domain, or have setup limits on your domain how how many items can be returned pr search you might have to use paging.

public static List<string> GetComputers()
{
    List<string> ComputerNames = new List<string>();

    DirectoryEntry entry = new DirectoryEntry("LDAP://YourActiveDirectoryDomain.no");
    DirectorySearcher mySearcher = new DirectorySearcher(entry);
    mySearcher.Filter = ("(objectClass=computer)");
    mySearcher.SizeLimit = int.MaxValue;
    mySearcher.PageSize = int.MaxValue;

    foreach(SearchResult resEnt in mySearcher.FindAll())
    {
    	//"CN=SGSVG007DC"
    	string ComputerName = resEnt.GetDirectoryEntry().Name;
    	if (ComputerName.StartsWith("CN="))
    		ComputerName = ComputerName.Remove(0,"CN=".Length);
            ComputerNames.Add(ComputerName);
        }

    	mySearcher.Dispose();
    	entry.Dispose();

        return ComputerNames;
}

--- -- ---- ------------------------------------------------------------------ ------ - -- -                          -- -             ---------------------

Get computers and domains in Active Directory

I want to recover a complete list of computers and the domains that they are in from Active Directory using the functionailty built in to .NET 2.0.  I have determined how to get ALL computers in the default domain using the following code:

// Identify the ‘default’ AD/LDAP Server
DirectoryEntry defaultServer = new DirectoryEntry(“LDAP://rootDSE”);
string strLdapServer = (string)defaultServer.Properties[“defaultNamingContext”].Value;
DirectoryEntry mySearchRoot = new DirectoryEntry(“LDAP://” + strLdapServer);

// Create a ‘DirectoryEntry’ object to search.
DirectorySearcher myDirectorySearcher = new DirectorySearcher(mySearchRoot);
myDirectorySearcher.Filter = (“(objectClass=computer)”);

// Iterate through (any) results
foreach(SearchResult resEnt in myDirectorySearcher.FindAll())
{
// Get the ‘DirectoryEntry’ that corresponds to ‘mySearchResult’.
DirectoryEntry myDirectoryEntry = resEnt.GetDirectoryEntry();
string strComputer = myDirectoryEntry.Name.ToString();
}

…and I have also determined code to recover a list of domains defined within AD as :

List<string> domains = new List<string>()
DirectoryEntry en = new DirectoryEntry(“LDAP://”);

// Search for objectCategory type “Domain”
DirectorySearcher srch = new DirectorySearcher(“objectCategory=Domain”);
SearchResultCollection coll = srch.FindAll();

// Enumerate over each returned domain.
foreach (SearchResult rs in coll)
{
ResultPropertyCollection resultPropColl = rs.Properties;
foreach (object domainName in resultPropColl[“name”])
{
domains.Add(domainName.ToString());
}
}

…now what I want to do is to use the name of the domain returned as above to recover the name of any computers within this domain.  I did try using the following code:

string ldapString = “LDAP://” + domainName + “/CN=Computers,DC=” + domainName + “,DC=com”;
DirectoryEntry domain = new DirectoryEntry(ldapString);
foreach (DirectoryEntry child in domain.Children)
{
string computerName = child.Name;
if (computerName != “”)
computers.Add(new string[] { computerName, domainName });
}

But this fails to connect to the AD server.  Ultimately I need some code which, given the domain name, is able to query the AD server for that domain and recover the list of computers on that domain but I seem to be having problems determining the correct LDAP string.

Chapter 52: Directory Services – http://blogs.wrox.com/article/directory-services/

Enumerate Global Catalogs in the Current Forest

public static ArrayList EnumerateDomains()
{
    ArrayList alGCs = new ArrayList();
    Forest currentForest = Forest.GetCurrentForest();
    foreach (GlobalCatalog gc in currentForest.GlobalCatalogs)
    {
        alGCs.Add(gc.Name);
    }
    return alGCs;
}

Enumerate Domain Controllers in a Domain

public static ArrayList EnumerateDomainControllers()
{
    ArrayList alDcs = new ArrayList();
    Domain domain = Domain.GetCurrentDomain();
    foreach (DomainController dc in domain.DomainControllers)
    {
        alDcs.Add(dc.Name);
    }
    return alDcs;
}

AD – Enumerate domains in the current forest

Enumerate domains in the current forest

public static ArrayList EnumerateDomains()
{
    ArrayList alDomains = new ArrayList();
    Forest currentForest = Forest.GetCurrentForest();
    DomainCollection myDomains = currentForest.Domains;

    foreach (Domain objDomain in myDomains)
    {
        alDomains.Add(objDomain.Name);
    }
    return alDomains;
}

just another line in the file Getting list of (sub-)domains from Active Directory with C#

http://www.janus-net.de/2005/11/18/getting-list-of-sub-domains-from-active-directory-with-c/

split comma 2

publicstaticIEnumerable<string>SplitCSV(string csvString){var sb =newStringBuilder();
    bool quoted =false;foreach(char c in csvString){if(quoted){if(c =='"')
                quoted =false;else
                sb.Append(c);}else{if(c =='"'){
                quoted =true;}elseif(c ==','){
                yield return sb.ToString();
                sb.Length=0;}else{
                sb.Append(c);}}}if(quoted)thrownewArgumentException("csvString","Unterminated quotation mark.");

    yield return sb.ToString();}