DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets

  • submit to reddit

Recent Snippets

                    //Mail Merge using PHP REST

// Build URI to execute mail merge
$strURI = 'http://api.aspose.com/v1.1/words/Sample.docx/executeMailMerge?withRegions=true&mailMergeDataFile=Data.xml';
// Use the following URI if you want to remove EmptyParagraphs,UnusedRegions,UnusedFields and ContainingFields during mail merge
// $strURI = 'http://api.aspose.com/v1.1/words/Sample.docx/executeMailMerge?mailMergeDataFile=Data.xml&cleanup=EmptyParagraphs,UnusedRegions,UnusedFields,ContainingFields';
/**** End Section 1 ****/

/**** Section 2 ****/
$appSID  = "77****-****-****-****-80*********";
$appKey = "****************";

// Sign URI
$signedURI = Sign($strURI, $appSID, $appKey);
/**** End Section 2 ****/

/**** Section 3 ****/
$responseStream = ProcessCommand($signedURI, "POST", "", "");
/**** End Section 3 ****/

/**** Section 4 ****/
$json = json_decode($responseStream);
//build URI to download output DOC
$outputFileName = $json->Document->FileName;
/**** End Section 4 ****/

//Mail Merge using PHP SDK

/**** Section 1 ****/

// Specify product URI Product::$baseProductUri = "http://api.aspose.com/v1.1"; //sepcify App SID AsposeApp::$appSID = "xxxxxxxxxxxxxxxxxxxxxxxx"; //sepcify App Key AsposeApp::$appKey = "xxxxxxxxxxxxxxxxxxxxxxxx";

/**** End Section 1 ****/

try{

/**** Section 2 ****/
AsposeApp::$outPutLocation = getcwd() . "/Output/";   $mainDocumentFile = getcwd() . "/Input/SimpleMerge.doc";   $mainDocument = basename($mainDocumentFile);   $xml = simplexml_load_file(getcwd() . "/Input/SimpleMerge.xml");
/**** End Section 2 ****/

/**** Section 3 ****/
//upload main document   echo "Uploading main document...<br />";   $folder = new Folder();   $folder->uploadFile($mainDocumentFile, "");   echo "Main document uploaded <br />";
/**** End Section 3 ****/

/**** Section 4 ****/
echo "Executing mail merge... <br />";   //create MailMerge object   $doc = new MailMerge();   $result = $doc->executeMailMerge($mainDocument, $xml->asXML());
/**** End Section 4 ****/ }

catch (Exception $e)
  {
    throw new Exception($e->getMessage());
  }

//«TableStart:TableName»«TableEnd:TableName» regions, use the following XML structure to send in the request body.

<?xml version="1.0" encoding="utf-8"?>
<CollectionName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ItemName>
        <field1>Value1</field1>
        <field2>Value2</field2>
    </ItemName>
    <ItemName>
        <field1>Value1</field1>
        <field2>Value2</field2>
    </ItemName>
</CollectionName>                
                    require 'open-uri'
require 'tmpdir'
require 'fileutils'
require 'digest'

def wget(url)
  cachedir = File.join( Dir.tmpdir, 'httpcache' )
  filename = File.join( cachedir, Digest::MD5.hexdigest(url) )
  
  FileUtils.mkdir_p(cachedir) if !File.exists?(cachedir)
  if File.exist?(filename)
    body = File.binread(filename)
  else
    body = open(url).read
    File.open(filename, "wb") do |saved_file|
      saved_file.write(body)
    end
  end

  body
end
                
                    require 'rbconfig'

def is_root?
  if RbConfig::CONFIG['host_os'] =~ /mswin|win32|dos|mingw|cygwin/i
    require 'win32/registry'
    
    begin
      Win32::Registry::HKEY_USERS.open('S-1-5-19') {|reg| }
      true
    rescue
      false
    end
  else
    (ENV['USER'] == 'root')
  end
end
                
                    # Sample 1: 
RewriteRule ^about$ about.php [L]
 
# Sample 2: 
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php                
                    # Source: http://www.apphp.com/index.php?snippet=htaccess-different-directory-index-page

# Sample 1: 
DirectoryIndex index2.html
 
# Sample 2: 
DirectoryIndex index2.php                
                    # Sample 1: 
DirectoryIndex index2.html
 
# Sample 2: 
DirectoryIndex index2.php                
                    -- 1st example
UPDATE files SET filepath = REPLACE(filepath,'path/to/search','path/to/replace');
 
-- 2nd example
UPDATE customers SET address = REPLACE(address,'_CODE_',postcode);                
                    <!-- First way -->
<input type="button" value="This is
a Really
Tall
 Button">
<!-- Second way -->
<button>This is<br/>a Really<br/>Tall<br/>Button</button>                
                    <!-- This is a comment. Comments are not displayed in the browser. -->
 
<div id="header">
   <p>Some text</p>
</div> <!-- END div-header -->
 
<script type="text/javascript">
<!--
function ShowMessage()
{
  alert("Hello World!")
}
//-->
</script>

                
                    //The Sample code shows how to export VSD to VDX

//[C# Sample]
 
//Call the diagram constructor to load diagram from a VSD file
Diagram diagram = new Diagram("D:\\Drawing1.vsd");
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.ContentType = "application/vnd.ms-visio";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vdx");
this.Response.Flush();
System.IO.Stream vdxStream = this.Response.OutputStream;

//Save input VSD as VDX
diagram.Save(vdxStream, SaveFileFormat.VDX);
this.Response.End();

//[VB.NET Code Sample]

'Call the diagram constructor to load diagram from a VSD file
Dim diagram As New Diagram("D:\Drawing1.vsd")

Me.Response.Clear()
Me.Response.ClearHeaders()
Me.Response.ContentType = "application/vnd.ms-visio"
Me.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vdx")
Me.Response.Flush()
Dim vdxStream As System.IO.Stream = Me.Response.OutputStream

'Save inpupt VSD as VDX
diagram.Save(vdxStream, SaveFileFormat.VDX)
Me.Response.End()

//The Sample code shows how to export VSD to VSX format.

[C# Code Sample]

// Call the diagram constructor to load diagram from a VSD file
Diagram diagram = new Diagram("D:\\Drawing1.vsd");
this.Response.Clear();
this.Response.ClearHeaders();
this.Response.ContentType = "application/vnd.ms-visio";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vsx");
this.Response.Flush();
System.IO.Stream vsxStream = this.Response.OutputStream;

//Save input VSD as VSX
diagram.Save(vsxStream, SaveFileFormat.VSX);
this.Response.End()

//[VB.NET Code Sample]

'Call the diagram constructor to load diagram from a VSD file
Dim diagram As New Diagram("D:\Drawing1.vsd")

Me.Response.Clear()
Me.Response.ClearHeaders()
Me.Response.ContentType = "application/vnd.ms-visio"
Me.Response.AppendHeader("Content-Disposition", "attachment; filename=Diagram.vsx")
Me.Response.Flush()
Dim vsxStream As System.IO.Stream = Me.Response.OutputStream

'Save input VSD as VSX
diagram.Save(vsxStream, SaveFileFormat.VSX)
Me.Response.End()