Monday, December 29, 2014

FTP via Command Prompt (Windows)

FTP via Command Prompt (Windows)
To FTP a particular server we have to perform following 2 operations:
  1. Connect to server.
  2. Download/Upload files.

To connect to server please following steps:
  1. Create a local directory (to upload and download files)
  2. Go to Command Prompt. Run > CMD > Enter
  3. Go to local directory using CD.. or CD\


  4. Run following command:
    1. ftp server_address and hit ENTER
  5. it will ask for username . enter username and hit ENTER
  6. now it will ask for password. Enter password and hit ENTER


now you are connected to server.
Use LS command to list all the files and directories on the server. Again to go to selected directory use CD command for example CD My_Dir.

To download file:
Use GET command to download file.

Similarly use PUT command to upload file to the desired location.

Same way we can upload multiple files and perform other FTP operations. Following are few commands for FTP:
Command
Information
!
This command toggles back and forth between the operating system and ftp.
Once back in the operating system, typing exit takes you back to the FTP command line.
?
Access the Help screen.
append
Append text to a local file.
ascii
Switch to ASCII transfer mode
bell
Turns bell mode on or off.
binary
Switches to binary transfer mode.
bye
Exits from FTP.
cd
Changes directory.
close
Exits from FTP.
delete
Deletes a file.
debug
Sets debugging on or off.
dir
Lists files if connected.

dir -C = Will list the files in wide format.
dir -1 = Lists the files in bare format in alphabetic order
dir -r = Lists directory in reverse alphabetic order.
dir -R = Lists all files in current directory and sub directories.
dir -S = Lists files in bare format in alphabetic order.
disconnect
Exits from FTP.
get
Get file from the computer connected to.
glob
Sets globbing on or off. When turned off the file name in the put and get 
commands is taken literally and wildcards will not be looked at.
hash
Sets hash mark printing on or off. 
When turned on for each 1024 bytes of data received a hash-mark (#) is displayed.
help
Access the Help screen and displays information about command 
if command typed after help.
lcd
Displays local directory if typed alone or if path typed after lcd will change local directory.
literal
Sends a literal command to the connected computer with an expected one line response.
ls
Lists files of the remotely connected computer.
mdelete
Multiple delete.
mdir
Lists contents of multiple remote directories.
mget
Get multiple files.
mkdir
Make directory.
mls
Lists contents of multiple remote directories.
mput
Sent multiple files
open
Opens address.
prompt
Enables or disables the prompt.
put
Send one file
pwd
Print working directory
quit
Exits from FTP.
quote
Same as the literal command.
recv
Receive file.
remotehelp
Get help from remote server.
rename
Renames a file.
rmdir
Removes a directory on the remote computer.
send
Send single file.
status
Shows status of currently enabled and disabled options
trace
Toggles packet tracing.
Type
Set file transfer type.
user
Send new user information.
verbose
Sets verbose on or off.

Disk Management Shortcut Run > Disk Management

Run > Disk Management.

Run following command to open Disk Management:

diskmgmt.msc

asp.net, jQuery: Search feature, Search with enter button click.

Following example will demonstrate the search functionality in asp.net page using jQuery. This will also work with enter button click:

<asp:Panel ID="Panel1" runat="server" DefaultButton="btnSearch">
<table style="width:100%;">
  <tr>
    <td style="vertical-align: top;">
      <input class="form-control" id="txtSearch" type="text" placeholder="Search.." /></td>
    <td style="width:35px;">
      <asp:ImageButton ID="btnSearch" ImageUrl="Images/search-icon.png"
        OnClientClick="javascript:return Search('txtSearch');" runat="server" />
    </td>
  </tr>
</table>
</asp:Panel>
Please Note: asp:Panel is used here to make functionality working with enter button click, that is why we have to take asp:ImageButton instead of any normal html button.
Following JavaScript Code will navigate to search page.

<script type="text/javascript">
    function Search(txtbox) {
        var pat = new RegExp('^([0-9a-zA-Z _]+)$');
        if (!pat.test($('#' + txtbox).val())) {
            alert('Please enter valid keyword to search');
            return false;
        }
        var value = $('#' + txtbox).val().replace(" ", "_");
        if (value == 'SEARCH') {
            alert('Please enter keyword to search');
            return false;
        }
        else if ($.trim(value) == '') {
            window.location = '<%=ReadConfig.SiteUrl %>Search.aspx?q=' + value;
        }
        else {
            window.location = '<%=ReadConfig.SiteUrl %>AllSearch.aspx';
        }
        return false;
    }
</script>

This will also check special characters in search field.

MVC Razor: Working with Hidden Fields. Set and Get Hidden Fields.

MVC Razor: Working with Hidden Fields. Set and Get Hidden Fields.
Following code will render a hidden field in MVC Razor view:

<div class="row">
    @using (Html.BeginForm("UpdateModelInfo", "Model", FormMethod.Post))
    {
        @Html.HiddenFor(p => p.ModelItem.Id)
        <div class="form-group col-xs-12">
            @Html.TextAreaFor(p => p.ModelItem.ModelInfo, new { @class = "css-class", rows = 25 })
        </div>
        <div class="col-xs-12">
            <button type="submit" onclick="javascript:GetVal();" class="btn-class">Get Val</button>
            <button type="submit" class="btn-class">Submit</button>
        </div>
    }
</div>
We can also update this hidden field like any other element using jQuery or JavaScript:

<script type="text/javascript">
    function GetVal() {
        alert($('#hdn').val());
    }
</script>
Following is the way to get hidden field value in controller:

[HttpPost]
public ActionResult UpdateMoreInfo(FormCollection collection)
{
    Core.models.Model modl = new Core.models.Families();
    var modlId = collection.GetValue("ModelItem.Id").AttemptedValue;
    var moreInfo = collection.GetValue("ModelItem.ModelInfo").AttemptedValue;
    //perform some other logic here
    Db.SaveChanges();

    return RedirectToAction("Edit", "Model", new { @id = modlId });
}

telerik RadEditor Remove unwanted tool buttons from Radeditor

We can remove unwanter buttons from telerik RadEditor using following code. We just need to specify all the buttons which we need in an editor and their order.


<telerik:RadEditor runat="server" ID="EditorImageUrl">
  <ImageManager ViewPaths="~/G/L,~/G/C" UploadPaths="~/G/L" DeletePaths="~/G/L" />
  <Tools>
            <telerik:EditorToolGroup Tag="MainToolbar">
                <telerik:EditorTool Name="FindAndReplace" />
                <telerik:EditorSeparator />
                <telerik:EditorTool Name="Undo" />
                <telerik:EditorTool Name="Redo" />
                <telerik:EditorSeparator />
                <telerik:EditorTool Name="Cut" />
                <telerik:EditorTool Name="Copy" />
                <telerik:EditorTool Name="Paste" ShortCut="CTRL+!" />
                <telerik:EditorTool Name="Bold" />
                <telerik:EditorTool Name="Italic" />
                <telerik:EditorTool Name="Underline" />
                <telerik:EditorSeparator />
                <telerik:EditorTool Name="ForeColor" />
                <telerik:EditorTool Name="BackColor" />
                <telerik:EditorSeparator />
                <telerik:EditorTool Name="FontName" />
                <telerik:EditorTool Name="RealFontSize" />
                <telerik:EditorSeparator />
                <telerik:EditorTool Name="ImageManager" />
            </telerik:EditorToolGroup>
  </Tools>

</telerik:RadEditor>

telerik RadEditor ImageManager: Display complete url of image instead of relative url.

ImageManager in Telerik RadEditor adds images to the editor but with related url. which could raise some issues with url rewriting. we can easily resolve this by using ContentFilters attribute. image manager in following editor will add images with complete url only.



<telerik:RadEditor runat="server" ID="EditorImageUrl" ContentFilters="DefaultFilters,MakeUrlsAbsolute">
  <ImageManager DeletePaths="~/DisplayImages" UploadPaths="~/DisplayImages" ViewPaths="~/DisplayImages" />

</telerik:RadEditor>

Telerik Radeditor: ImageManager - display images from multiple folder.

use following code to include ImageManager to a RadEditor and display images from multiple folders:

<telerik:RadEditor ID="RadEditor1" Height="600" runat="server">
  <ImageManager ViewPaths="~/Images/ProfilePics,~/Images/PublicPics" UploadPaths="~/Images/ProfilePics" DeletePaths="~/Images/ProfilePics" />
</telerik:RadEditor>

Friday, December 26, 2014

Get all checkbox checked in gridview/repeater/datalist

Following is the simplest way to get checked checkbox in a grid:

<asp:GridView runat="server" ID="grd" AutoGenerateColumns="false">
  <EmptyDataTemplate>
    No data found
  </EmptyDataTemplate>
  <Columns>
    <asp:TemplateField HeaderStyle-Width="4%">
      <HeaderTemplate>
        <input type="checkbox" id="cbUserAll" title="Select/Unselect All" onclick="SelectAllCB('ckbUser', this);" />
      </HeaderTemplate>
      <ItemTemplate>
        <input type="checkbox" id='ckbUser<%#Eval("Id")%>' name="ckbUser" value='<%#Eval("Id")%>' />
      </ItemTemplate>
In CS page:
  string str = Convert.ToString(Request.Form["ckbuser"]);

This will get all selected checkbox values comma separated.