working on it ...

Filters

Explore Public Snippets

Sort by

Found 6,463 snippets matching: inside

    public by HeathDernovich  265153  0  4  1

    Simple caching inside of session storage...

    Simple caching inside of session storage...: seshCache.js
    // session storage caching
    
    define(function() {
    
        var cacheObj = window.sessionStorage || {
            getItem: function(key) {
                return this[key];
            },
            setItem: function(key, value) {
                this[key] = value;
            }
        };
    
        return {
            get: function(key) {
                return this.isFresh(key);
            },
            set: function(key, value, minutes) {
                var expDate = new Date();
                expDate.setMinutes(expDate.getMinutes() + (minutes || 0));
    
                try {
                    cacheObj.setItem(key, JSON.stringify({
                        value: value,
                        expires: expDate.getTime()
                    }));
                }
                catch(e) { }
            },
            isFresh: function(key) {
                // value or false
                var item;
                try {
                    item = JSON.parse(cacheObj.getItem(key));
                }
                catch(e) {}
                if(!item) return false;
                return new Date().getTime() > item.expires ? false : item.value;
            }
         }
    });
    
    
    // Use it
    require(['storage'], function(storage) {
        var content = storage.get('sidebarContent');
        if(!content) {
            // request to get content & store for 1 hr
            storage.set('sidebarContent', content, 60); 
        }
    });
    
    

    public by sherazam  228301  0  5  0

    How to Insert Check Boxes or HTML into Word Docs during Mail Merge inside .NET Apps

    How to Insert Check Boxes or HTML into Word Docs during Mail Merge inside .NET Apps
    // Enter here the actual content of the snippet.            
    //[C# Code Sample]
     
    using System;
    using System.IO;
    using System.Reflection;
    using Aspose.Words;
    using Aspose.Words.Fields;
    using Aspose.Words.MailMerging;
    
    namespace MailMergeFormFields
    {
        /// <summary>
        /// This sample shows how to insert check boxes and text input form fields during mail merge into a document.
        /// </summary>
        class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            public static void Main(string[] args)
            {
                Program program = new Program();
                program.Execute();
            }
    
            private void Execute()
            {
                string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
                string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath;
    
                // Load the template document.
                Document doc = new Document(dataDir + "Template.doc");
    
                // Setup mail merge event handler to do the custom work.
                doc.MailMerge.FieldMergingCallback = new HandleMergeField();
    
                // This is the data for mail merge.
                String[] fieldNames = new String[] {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber",
                    "Subject", "Body", "Urgent", "ForReview", "PleaseComment"};
                Object[] fieldValues = new Object[] {"Josh", "Jenny", "123456789", "", "Hello",
                    "<b>HTML Body Test message 1</b>", true, false, true};
    
                // Execute the mail merge.
                doc.MailMerge.Execute(fieldNames, fieldValues);
    
                // Save the finished document.
                doc.Save(dataDir + "Template Out.doc");
            }
    
            private class HandleMergeField : IFieldMergingCallback
            {
                /// <summary>
                /// This handler is called for every mail merge field found in the document,
                ///  for every record found in the data source.
                /// </summary>
                void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
                {
                    if (mBuilder == null)
                        mBuilder = new DocumentBuilder(e.Document);
    
                    // We decided that we want all boolean values to be output as check box form fields.
                    if (e.FieldValue is bool)
                    {
                        // Move the "cursor" to the current merge field.
                        mBuilder.MoveToMergeField(e.FieldName);
    
                        // It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
                        string checkBoxName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);
    
                        // Insert a check box.
                        mBuilder.InsertCheckBox(checkBoxName, (bool)e.FieldValue, 0);
    
                        // Nothing else to do for this field.
                        return;
                    }
    
                    // We want to insert html during mail merge.
                    if (e.FieldName == "Body")
                    {
                        mBuilder.MoveToMergeField(e.FieldName);
                        mBuilder.InsertHtml((string)e.FieldValue);
                    }
    
                    // Another example, we want the Subject field to come out as text input form field.
                    if (e.FieldName == "Subject")
                    {
                        mBuilder.MoveToMergeField(e.FieldName);
                        string textInputName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);
                        mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", (string)e.FieldValue, 0);
                    }
                }
    
                void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
                {
                    // Do nothing.
                }
    
                private DocumentBuilder mBuilder;
            }
        }
    }
     
    //[VB.NET Code Sample]
     
    
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.IO
    Imports System.Reflection
    Imports Aspose.Words
    Imports Aspose.Words.Fields
    Imports Aspose.Words.MailMerging
    
    Namespace MailMergeFormFields
        ''' <summary>
        ''' This sample shows how to insert check boxes and text input form fields during mail merge into a document.
        ''' </summary>
        Friend Class Program
            ''' <summary>
            ''' The main entry point for the application.
            ''' </summary>
            Public Shared Sub Main(ByVal args() As String)
                Dim program As New Program()
                program.Execute()
            End Sub
    
            Private Sub Execute()
                Dim exeDir As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar
                Dim dataDir As String = New Uri(New Uri(exeDir), "../../Data/").LocalPath
    
                ' Load the template document.
                Dim doc As New Document(dataDir & "Template.doc")
    
                ' Setup mail merge event handler to do the custom work.
                doc.MailMerge.FieldMergingCallback = New HandleMergeField()
    
                ' This is the data for mail merge.
                Dim fieldNames() As String = {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber", "Subject", "Body", "Urgent", "ForReview", "PleaseComment"}
                Dim fieldValues() As Object = {"Josh", "Jenny", "123456789", "", "Hello", "<b>HTML Body Test message 1</b>", True, False, True}
    
                ' Execute the mail merge.
                doc.MailMerge.Execute(fieldNames, fieldValues)
    
                ' Save the finished document.
                doc.Save(dataDir & "Template Out.doc")
            End Sub
    
            Private Class HandleMergeField
                Implements IFieldMergingCallback
                ''' <summary>
                ''' This handler is called for every mail merge field found in the document,
                '''  for every record found in the data source.
                ''' </summary>
                Private Sub IFieldMergingCallback_FieldMerging(ByVal e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging
                    If mBuilder Is Nothing Then
                        mBuilder = New DocumentBuilder(e.Document)
                    End If
    
                    ' We decided that we want all boolean values to be output as check box form fields.
                    If TypeOf e.FieldValue Is Boolean Then
                        ' Move the "cursor" to the current merge field.
                        mBuilder.MoveToMergeField(e.FieldName)
    
                        ' It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
                        Dim checkBoxName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)
    
                        ' Insert a check box.
                        mBuilder.InsertCheckBox(checkBoxName, CBool(e.FieldValue), 0)
    
                        ' Nothing else to do for this field.
                        Return
                    End If
    
                    ' We want to insert html during mail merge.
                    If e.FieldName = "Body" Then
                        mBuilder.MoveToMergeField(e.FieldName)
                        mBuilder.InsertHtml(DirectCast(e.FieldValue, String))
                    End If
    
                    ' Another example, we want the Subject field to come out as text input form field.
                    If e.FieldName = "Subject" Then
                        mBuilder.MoveToMergeField(e.FieldName)
                        Dim textInputName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)
                        mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", CStr(e.FieldValue), 0)
                    End If
                End Sub
    
                Private Sub ImageFieldMerging(ByVal args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging
                    ' Do nothing.
                End Sub
    
                Private mBuilder As DocumentBuilder
            End Class
        End Class
    End Namespace
    
    

    public by johansonkatherine  219700  1  6  2

    C# Code Sample to Replace Multiple Texts inside PDF File Using Cloud API

    The following code sample shows how developers can replace multiple texts in a single API call in a PDF file using Aspose.Pdf for Cloud API in their applications. Developers can use Aspose REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
    AsposeApp.AppSID  = "77***********************************";
    AsposeApp.AppKey = "9a*******************************";
    
    //build URI
    stringstrURI = "http://api.aspose.com/v1.1/pdf/test.pdf/replaceTextList";
    
    //sign URI
    stringsignedURI = Utils.Sign(strURI);
    
    //build JSON to post
    TextReplace textReplace1 = new TextReplace();
    textReplace1.OldValue = "[!firm!]";
    textReplace1.NewValue = "Aspose";
    textReplace1.Regex = "false";
    
    //build JSON to post
    TextReplace textReplace2 = new TextReplace();
    textReplace2.OldValue = "[!client!]";
    textReplace2.NewValue = "Mark";
    textReplace2.Regex = "false";
    
    MultipleTextReplacestextReplaces = new MultipleTextReplaces();
    textReplaces.TextReplaces = new TextReplace[] { textReplace1, textReplace2 };
    stringstrJSON = JsonConvert.SerializeObject(textReplaces);
    Console.Write(strJSON);
    Utils.ProcessCommand(signedURI, "POST", strJSON);
    
    //build URI
    strURI = "http://api.aspose.com/v1.1/storage/file/test.pdf";
    
    //sign URI
    signedURI = Utils.Sign(strURI);
    
    Stream responseStream = Utils.ProcessCommand(signedURI, "GET");
    using (Stream fileStream = System.IO.File.OpenWrite(@"test.pdf"))
    {
    Utils.CopyStream(responseStream, fileStream);
    }
    responseStream.Close();
    
    //Following are required classes
    public class MultipleTextReplaces
        {
    publicTextReplace[] TextReplaces { get; set; }
        }
    public class TextReplace
        {
    publicTextReplace() { }
    
    public string OldValue { get; set; }
    public string NewValue { get; set; }
    public string Regex { get; set; }
    
        }
    

    public by sherazam  184663  0  5  0

    How to Render an Image of 3D Model from the Camera inside .NET Application

    This Technical tip explains how .NET developers can render an image of 3D model from the camera inside their .NET applications. Using Aspose.3D for .NET, developers can render an image to view a realistic image of 3D model, with or without the enhanced background, textures, shadows and also adjust the image size. The Render method exposed by the Sc
    // Enter here the actual content of the snippet.            // this code example creates a camera in a 3D scene, sets its target and render an image.
    
    // [C# Code Sample]
    
    // For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
    // The path to the documents directory.
    string MyDir = RunExamples.GetDataDir();
    
    // Load scene from file
    Scene scene = new Scene(MyDir + "camera.3ds");
    // Create a camera at (10,10,10) and look at the origin point for rendering,
    // it must be attached to the scene before render
    Camera camera = new Camera();
    scene.RootNode.CreateChildNode("camera", camera);
    camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
    camera.LookAt = Vector3.Origin;
    
    // Specify the image render option
    ImageRenderOptions opt = new ImageRenderOptions();
    // Set the background color
    opt.BackgroundColor = Color.AliceBlue;
    // Tells renderer where the it can find textures
    opt.AssetDirectories.Add(MyDir + "textures");
    // Turn on shadow
    opt.EnableShadows = true;
    // Render the scene in given camera's perspective into specified png file with size 1024x1024
    scene.Render(camera, MyDir + "Render3DModelImageFromCamera_out_.png", new Size(1024, 1024), ImageFormat.Png, opt);
    
    //[VB.NET Code Sample]
    
    ' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
    ' The path to the documents directory.
    Dim MyDir As String = RunExamples.GetDataDir()
    
    ' Load scene from file
    Dim scene As New Scene(MyDir & Convert.ToString("camera.3ds"))
    ' Create a camera at (10,10,10) and look at the origin point for rendering,
    ' it must be attached to the scene before render
    Dim camera As New Camera()
    scene.RootNode.CreateChildNode("camera", camera)
    camera.ParentNode.Transform.Translation = New Vector3(10, 10, 10)
    camera.LookAt = Vector3.Origin
    
    ' Specify the image render option
    Dim opt As New ImageRenderOptions()
    ' Set the background color
    opt.BackgroundColor = Color.AliceBlue
    ' Tells renderer where the it can find textures
    opt.AssetDirectories.Add(MyDir & Convert.ToString("textures"))
    ' Turn on shadow
    opt.EnableShadows = True
    ' Render the scene in given camera's perspective into specified png file with size 1024x1024
    scene.Render(camera, MyDir & Convert.ToString("Render3DModelImageFromCamera_out_.png"), New Size(1024, 1024), ImageFormat.Png, opt)
    

    public by LaurenceTamatea  127763  0  4  0

    Variable Inside Function

    <!DOCTYPE html>
    <!--
    To change this license header, choose License Headers in Project Properties.
    To change this template file, choose Tools | Templates
    and open the template in the editor.
    -->
    <html>
        <head>
            <title>Global and Local Variables</title>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
        </head>
        <body>
            <div>Global and Local Variables</div>
            
            <script>
          
           function houseTypes () {
               var houses = "one storey";
               document.write (houses);
               
           }
           
           houseTypes ();
           
            </script>
        </body>
    </html>       

    public by sherazam  120627  0  5  0

    How to Set Line Spacing of a Paragraph in an Excel Shape or Textbox inside .NET Apps

    This technical tip shows how to Set Line Spacing of the Paragraph in a Shape or Textbox in .NET applications. You can set the line space of the paragraph, its space before and space after using the TextParagraph.LineSpace, TextParagraph.SpaceBefore and TextParagraph.SpaceAfter respectively. The following example shows how to Set Line Spacing of the
    // Enter here the actual content of the snippet.            
    
    //[C# Code]
     
    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    
    // Create a workbook
    Workbook wb = new Workbook();
    
    // Access first worksheet
    Worksheet ws = wb.Worksheets[0];
    
    // Add text box inside the sheet
    ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200);
    
    // Access first shape which is a text box and set is text
    Shape shape = ws.Shapes[0];
    shape.Text = "Sign up for your free phone number.\nCall and text online for free.";
    
    // Acccess the first paragraph
    TextParagraph p = shape.TextBody.TextParagraphs[1];
    
    // Set the line space
    p.LineSpaceSizeType = LineSpaceSizeType.Points;
    p.LineSpace = 20;
    
    // Set the space after
    p.SpaceAfterSizeType = LineSpaceSizeType.Points;
    p.SpaceAfter = 10;
    
    // Set the space before
    p.SpaceBeforeSizeType = LineSpaceSizeType.Points;
    p.SpaceBefore = 10;
    
    // Save the workbook in xlsx format
    wb.Save(dataDir + "output_out_.xlsx", SaveFormat.Xlsx); 
    
    //[VB.NET Code]
    
    ' For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
    ' The path to the documents directory.
    Dim dataDir As String = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
    
    ' Create a workbook
    Dim wb As New Workbook()
    
    ' Access first worksheet
    Dim ws As Worksheet = wb.Worksheets(0)
    
    ' Add text box inside the sheet
    ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200)
    
    ' Access first shape which is a text box and set is text
    Dim shape As Shape = ws.Shapes(0)
    shape.Text = "Sign up for your free phone number." & vbLf & "Call and text online for free."
    
    ' Acccess the first paragraph
    Dim p As TextParagraph = shape.TextBody.TextParagraphs(1)
    
    ' Set the line space
    p.LineSpaceSizeType = LineSpaceSizeType.Points
    p.LineSpace = 20
    
    ' Set the space after
    p.SpaceAfterSizeType = LineSpaceSizeType.Points
    p.SpaceAfter = 10
    
    ' Set the space before
    p.SpaceBeforeSizeType = LineSpaceSizeType.Points
    p.SpaceBefore = 10
    
    ' Save the workbook in xlsx format
    wb.Save(dataDir & Convert.ToString("output_out_.xlsx"), SaveFormat.Xlsx) 
    
    

    public by Geometry  112766  0  6  0

    DeepClone: Copies a collection by calling the ICloneable.Clone method for each element inside it.

    Copies a collection by calling the ICloneable.Clone method for each element inside it. yThe collection to be cloned. A copy of the collection where each element has also been copied.
    /// <summary>
    ///   Copies a collection by calling the ICloneable.Clone method for each element inside it.
    /// </summary>
    /// 
    /// <typeparam name="T"></typeparam>
    /// <param name="list">The collection to be cloned.</param>
    /// 
    /// <returns>A copy of the collection where each element has also been copied.</returns>
    /// 
    public static T DeepClone<T>(this T list)
        where T : IList<ICloneable>, ICloneable
    {
        T clone = (T)list.Clone();
        for (int i = 0; i < clone.Count; i++)
            clone[i] = (ICloneable)list[i].Clone();
        return clone;
    }

    public by cghersi  3482  8  7  0

    C#: how to wrap a text inside a given length

    This method helps in wrapping the given text moving the word that pass the threshold to the next line
    static public string WrapText(string inputText, int minLenght, int maxLength)
    {
        // bool ignoreWrap = false;
        string wrappedText = string.Empty;
    
        string[] lines = inputText.Split(new char[] { '\n' });
        foreach (string line in lines)
        {
            string[] words = line.Split(new char[] { ' ', '\r' });
            int lineCounter = 0;
            foreach (string word in words)
            {
                if (word.Trim().Length == 0)
                    continue;
    
                // Next word will pass the max line length => add a newLine
                if (lineCounter + word.Length + 1 >= maxLength)
                {
                    // Split a single word that is longer than the line
                    if (word.Length >= maxLength)
                    {
                        int fragments = word.Length / maxLength + 1;
                        int fragmentStart = 0;
                        int fragmentLength = 0;
                        for (int t = 0; t < fragments; t++)
                        {
                            fragmentLength = (word.Length - fragmentStart > maxLength) ? maxLength : word.Length - fragmentStart;
                            if (lineCounter > 0)
                                wrappedText += Environment.NewLine + word.Substring(fragmentStart, fragmentLength);
                            else
                                wrappedText += word.Substring(fragmentStart, fragmentLength);
                            fragmentStart += fragmentLength;
                        }
                        if (fragmentLength < maxLength)
                        {
                            wrappedText += " ";
                            lineCounter = fragmentLength + 1;
                        }
                        else
                        {
                            wrappedText += Environment.NewLine;
                            lineCounter = 0;
                        }
                        continue;
                    }
                    wrappedText += Environment.NewLine;
                    lineCounter = 0;
                }
                wrappedText += word;
                wrappedText += " ";
                lineCounter += word.Length + 1;
            }
            wrappedText += Environment.NewLine;
        }
        return wrappedText;
    }

    public by cghersi  2707  1  6  3

    How to query some values inside XML in SQL Server

    This query relies on 'value' operator applied on XML fields. You can directly transform the resulting value into a particular type with the second parameter of this function.
    WITH XMLNAMESPACES ('http://www.snip2code.com/namespaces/s2c' AS s2c)
    SELECT  field1, field2
    FROM    MyTable
    WHERE   MyXMLField.value('/s2c:root/fieldName != ""', 'bit') = 1      
    
    WITH XMLNAMESPACES ('http://www.snip2code.com/namespaces/s2c' AS s2c)
    SELECT  field1, field2
    FROM    MyTable
    WHERE   MyXMLField.value('(/s2c:root/fieldName/text())[1]', 'varchar(100)') = 'some text'

    public by sTiLL-iLL  2201  0  5  11

    Simple caching inside of session storage...

    Simple caching inside of session storage...: seshCache.js
    // session storage caching
    
    define(function() {
    
        var cacheMe = window.sessionStorage || {
            getOne: function(key) {
                return this[key];
            },
            setOne: function(key, value) {
                this[key] = value;
            }
        };
    
        return {
            get: function(key) {
                return this.isRdy(key);
            },
            set: function(key, value, minutes) {
                var xDate = new Date();
                xDate.setMinutes(xDate.getMinutes() + (minutes || 0));
    
                try {
                    cacheMe.setOne(key, JSON.stringify({
                        value: value,
                        expires: xDate.getTime()
                    }));
                }
                catch(err) {
                  console.log(err.message);
                }
            },
            isRdy: function(key) {
                var itm;
                try {
                    itm = JSON.parse(cacheMe.getItem(key));
                }
                catch(err) {
                  console.log(err.message);
                }
                
                if(!itm){
                   return false;
                }
    
                return new Date().getTime() > itm.expires ? false : itm.value;
            }
         }
    });
    
    // Use it...
    require(['storage'], function(storage) {
        var content = storage.get('content');
        if(!content) {
            // get the content, store content 1 hr
            storage.set('content', content, 60); 
        }
    });
    
    
    • Public Snippets
    • Channels Snippets