Removing HTML tags from string C# ASP


Here is the simple C# program that is used to remove HTML tags from a string, with very simple while and if else statement.
Here is code (C# function):
public static string RemoveHtmlTags(string content){
            char[] array = new char[content.Length];
            int arrayIndex = 0;
            bool inside = false;

            for (int i = 0; i < content.Length; i++)
            {
                char let = content[i];
                if (let == '<')
                {
                    inside = true;
                    continue;
                }
                if (let == '>')
                {
                    inside = false;
                    continue;
                }
                if (!inside)
                {
                    array[arrayIndex] = let;
                    arrayIndex++;
                }
            }
            return new string(array, 0, arrayIndex);
}
thanks g.
:)
Read more ...
7/21/2016
Post Was Published On

7/21/2016

Jaskaran SH SD

Posted in

Spread the love

C# Dynamic Streaming Video via Handler (.ashx) with Range Downloader ASP MVC

This tutorial is to show that how video playing is possible via a dynamic URL and hiding obsolete base URL. We have added to basic programs in it one is ProcessRequest() used to get file and process data o the file via streamer, second is RangeDownload(), which is required to download video http-range.

here is the full source class in .ashx file i used.

with following mysite.com/watch.ashx?id=1039 returns a video file.


public class Video : IHttpHandler {

    public void RangeDownload(int id, HttpContext context)
    {

        //connecton to database
        VideosDB db = new VideosDB();
        //Entity
        var get = db.MyvideosDB.FirstOrDefault(p => p.Video == id);
        //path to video ile
        string fullpath = context.Server.MapPath("~/cdn_users/" + get.Postedby + "/" + get.VideoURL);
        long size, start, end, length, fp = 0;
        using (StreamReader reader = new StreamReader(fullpath))
        {

            size = reader.BaseStream.Length;
            start = 0;
            end = size - 1;
            length = size;

            context.Response.AddHeader("Accept-Ranges", "0-" + size);

            if (!String.IsNullOrEmpty(context.Request.ServerVariables["HTTP_RANGE"]))
            {
                long anotherStart = start;
                long anotherEnd = end;
                string[] arr_split = context.Request.ServerVariables["HTTP_RANGE"].Split(new char[] { Convert.ToChar("=") });
                string range = arr_split[1];

                if (range.IndexOf(",") > -1)
                {
                    context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size);
                    throw new HttpException(416, "Requested Range Not Satisfiable");

                }

                if (range.StartsWith("-"))
                {
                    anotherStart = size - Convert.ToInt64(range.Substring(1));
                }
                else
                {
                    arr_split = range.Split(new char[] { Convert.ToChar("-") });
                    anotherStart = Convert.ToInt64(arr_split[0]);
                    long temp = 0;
                    anotherEnd = (arr_split.Length > 1 && Int64.TryParse(arr_split[1].ToString(), out temp)) ? Convert.ToInt64(arr_split[1]) : size;
                }
                anotherEnd = (anotherEnd > end) ? end : anotherEnd;
                if (anotherStart > anotherEnd || anotherStart > size - 1 || anotherEnd >= size)
                {

                    context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size);
                    throw new HttpException(416, "Requested Range Not Satisfiable");
                }
                start = anotherStart;
                end = anotherEnd;

                length = end - start + 1;
                fp = reader.BaseStream.Seek(start, SeekOrigin.Begin);
                context.Response.StatusCode = 206;
            }
        }
        context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size);
        context.Response.AddHeader("Content-Length", length.ToString());
        context.Response.WriteFile(fullpath, fp, length);
        context.Response.End();

    }

    public void ProcessRequest(HttpContext context)
    {
        string id = context.Request["id"];
        int newid;
        int.TryParse(id, out newid);

       
        VideosDB db = new VideosDB();

        var get = db.MyvideosDB.FirstOrDefault(p => p.Video == newid);

        string mimetype = "video/mp4";
        string fullpath=context.Server.MapPath("/cdn_users/"+get.Postedby+"/"+get.VideoURL);       
        if (System.IO.File.Exists(fullpath))
        {
           
            context.Response.ContentType = mimetype;
            if (!String.IsNullOrEmpty(context.Request.ServerVariables["HTTP_RANGE"]))
            {
                RangeDownload(newid, context);
            }
            else
            {
                long fileLength = File.OpenRead(fullpath).Length;
                context.Response.AddHeader("Content-Length", fileLength.ToString());
                context.Response.WriteFile(fullpath);            
            }
        }
        else
        {
            throw new HttpException(404, "Video Not Found Path:"+fullpath);
        }
    }
   
    public bool IsReusable {
        get {
            return false;
        }
    }

}

Thanks g . Keep Visiting.
Read more ...
7/21/2016
Post Was Published On

7/21/2016

Jaskaran SH SD

Posted in

,

Spread the love

Program to implement Linked List using Struct in C/C++

Today i am going to show you how to implement linked list  type data array using structure. Linked ist is type of data structure in which dynamic memory allocation takes place, in short it is a type of flexible data array

Lets see:

#include "stdafx.h"
#include <iostream>
using namespace std;

struct Node
{
    int info;
    Node *next;

}*HEAD, *TPTR, *NEWN;

void case1(){
    int getinfo;
    cin >> getinfo;
    NEWN = new Node;
    NEWN->info = getinfo;
    NEWN->next = NULL;
    if (HEAD == NULL){
        HEAD = NEWN;
        cout << "Node added";
    }
    else
    {
        TPTR->next = NEWN;
    }

}
void case2(){
    int getinfo, found = 0;
    cout << "Elemnt to serach" << endl;
    cin >> getinfo;
    if (HEAD != NULL){

        TPTR = HEAD;
        while (TPTR->next != NULL)
        {
            if (TPTR->info == getinfo){
                cout << "Elemnt found" << endl;
                found = 1;
            }
            TPTR = TPTR->next;
        }
        if (TPTR->info == getinfo){
            cout << "Elemnt found" << endl;
        }
        else if (found == 0){
            cout << "not found" << endl;
        }
    }

    else {
        cout << "linked List empty" << endl;
    }
}
void case3(){
    if (HEAD != NULL){
        TPTR = HEAD;
        while (TPTR->next != NULL)
        {
            cout << " ELemnt is " << TPTR->info <<endl;
            TPTR = TPTR->next;
        }
        cout << " ELemnt is " << TPTR->info<<endl;
    }
    else
    {
        cout << "Empty" << endl;
    }
}


void main(){
    int opt = 0, getinfo, found = 0;
    while (opt != 4)
    {
        if (HEAD != NULL){
            TPTR = HEAD;

            while (TPTR->next != NULL)
            {
                TPTR = TPTR->next;//tptr points to last
            }
        }
        cout << "Choose an option " << endl << "1. Insert element" << endl << "2. Find Element" <<endl<<"3. List all"<< endl<<"4. Exit";
        cin >> getinfo;
        opt = getinfo;
        switch(opt){
        case 1:
            case1();
            break;
        case 2:
            case2();
            break;
        case 3:
            case3();
            break;
        case 4:
            opt = 4;
            break;
        default:
            cout << "error";
            break;
        }
        opt = 0;
    }

}

Read more ...
7/10/2016
Post Was Published On

7/10/2016

Jaskaran SH SD

Posted in

Spread the love

C++ Program to Print Day of week using Date Input [LONG METHOD]

hello, Friends here goes a new C++ program to Print day of week using date input. We haven't used any shortcut method, program is made upon a long descriptive method.

lets see how program moves:




Thankyou, Post any mistake in the comments section.

Keep visiting BuildNextWeb
Read more ...
7/06/2016
Post Was Published On

7/06/2016

Jaskaran SH SD

Posted in

Spread the love

C / C++ Program to Print First 30 Prime Numbers


CELEBRATING :: BuildNextWeb's 100th post and first 1 Lacs viewers  
Here we start with a new topic to buildnextweb, Introducing C and C++ programing to buildnextweb. Contributors of Buildnextweb will now posting Basic to advance programs of C and C++. 
In this article we will be dealing with a simple program to print first 30 prime numbers using C / C++.

Here is the code snippets :


#include <iostream>
#include <conio.h>
using namespace std;
int IsPrime(int a){
int p = 1;
for (int i = 2; i < a; i++){
if (a%i == 0){
p = 0;
}
}
return p;
}
int main()
{
int counted = 1, c, i=1;
while ( counted !=30)
{
c = IsPrime(i);
if (c == 1){
cout << i << endl;
counted++;
}
c = 0;
i++;
}
cin >> c;
}
Output of the program : 


Thankuh so much.
  
Read more ...
6/13/2016
Post Was Published On

6/13/2016

Jaskaran SH SD

Posted in

Spread the love

A simple Page Number System for ASP.NEt C# / MVC


So here we introduce a whole new simple system of making  a page number system to ASP.NET c# MVC. Page Number concept is used to show a fixed size results on multiple pages. It allows us to Split the larger database in the smaller systems and thus even reduce the load to the particular page.

Concept used here for paging system is very simple we will use two major variable namely startIndex and PageSzie. Start-index will be determine the the starting point of the database will vary from page to page on the other hand Pagesize will determine the number of results to be picked form the database sources .

Well, what is the data source? Your action could take a few defaulted arguments, i.e.

ActionResult Search(string query, int startIndex, int pageSize) {...}

defaulted in the routes setup so that startIndex is 0 and pageSize is (say) 20:(You can skip this)

        routes.MapRoute("Search", "Search/{query}/{startIndex}",
                        new
                        {
                            controller = "Home", action = "Search",
                            startIndex = 0, pageSize = 20
                        });

To split the feed, you can use LINQ quite easily:

var page = source.Skip(startIndex).Take(pageSize);

(or do a multiplication if you use "pageNumber" rather than "startIndex")

With LINQ-toSQL, EF, etc - this should "compose" down to the database, too.

You should then be able to use action-links to the next page (etc):

<%=Html.ActionLink("next page", "Search", new {
                query, startIndex = startIndex + pageSize, pageSize }) %>
or for the razor syntax

@Html.ActionLink("next page", "Search", new {
                query, startIndex = startIndex + pageSize, pageSize })
so this system can help you to create a simple paging system.
thanks g.
Read more ...
4/10/2016
Post Was Published On

4/10/2016

Jaskaran SH SD

Posted in

Spread the love

New Unique Random Code Generator with Constant Beginning value ASP.NET/C#


Here is the exciting new Unique code generator for C# for .NET programmers. unlike the other random code generators this generator has more uniqueness even you can give some insistingly a constant value.
This code uses the default random() function and also modulus of 2 is checked and random code is generated for the given random condition. Finally the Number is converted to string and also concatenated  with the string to generate the random number.

Random uni1 = new Random();
     
        string s = "BNW";
        int uni;
        int n = 0;
        while (n < 10)
        {
            if (n % 2 == 0)
            {
                s += uni1.Next(10).ToString();

            }
            else
            {
                uni = uni1.Next(52);
                if (uni < this.characters.Length)
                    s = String.Concat(s, this.characters[unique]);
            }
            model.Text = s.ToString();
            n++;
           
        }
Hopefully it helps you. Drop your Suggestions to Comments.
Thanks g.
Read more ...
4/07/2016
Post Was Published On

4/07/2016

Jaskaran SH SD

Posted in

Spread the love