파일다운로드

 

http://www.codeguru.com/columns/dotnettips/article.php/c7005

 

// Remember to add the following using statements to your code
// using System.Net;
// using System.IO;

public static int DownloadFile(String remoteFilename,
                               String localFilename)
{
  // Function will return the number of bytes processed
  // to the caller. Initialize to 0 here.
  int bytesProcessed = 0;

  // Assign values to these objects here so that they can
  // be referenced in the finally block
  Stream remoteStream  = null;
  Stream localStream   = null;
  WebResponse response = null;

  // Use a try/catch/finally block as both the WebRequest and Stream
  // classes throw exceptions upon error
  try
  {
    // Create a request for the specified remote file name
    WebRequest request = WebRequest.Create(remoteFilename);
    if (request != null)
    {
      // Send the request to the server and retrieve the
      // WebResponse object
      response = request.GetResponse();
      if (response != null)
      {
        // Once the WebResponse object has been retrieved,
        // get the stream object associated with the response's data
        remoteStream = response.GetResponseStream();

        // Create the local file
        localStream = File.Create(localFilename);

        // Allocate a 1k buffer
        byte[] buffer = new byte[1024];
        int bytesRead;

        // Simple do/while loop to read from stream until
        // no bytes are returned
        do
        {
          // Read data (up to 1k) from the stream
          bytesRead = remoteStream.Read (buffer, 0, buffer.Length);

          // Write the data to the local file
          localStream.Write (buffer, 0, bytesRead);

          // Increment total bytes processed
          bytesProcessed += bytesRead;
        } while (bytesRead > 0);
      }
    }
  }
  catch(Exception e)
  {
    Console.WriteLine(e.Message);
  }
  finally
  {
    // Close the response and streams objects here
    // to make sure they're closed even if an exception
    // is thrown at some point
    if (response     != null) response.Close();
    if (remoteStream != null) remoteStream.Close();
    if (localStream  != null) localStream.Close();
  }

  // Return total bytes processed to caller.
  return bytesProcessed;

 

Finally, here's an example of using the DownloadFile function.

int read = DownloadFile("http://www.mysite.com/problem1.jpg",
                        "d:\\test.jpg");
Console.WriteLine("{0} bytes written", read);

http://www.codeplex.com/wlwSyntaxHighlighter

 

 

Writer 를 쓰시는 분들을 위한 SyntaxHighlighter

 

Windows Live Writer.png
Insert window:
Code.png
Plugin options:
SyntaxHighlighter Options.png
SyntaxHighlighter Options (2).png

How to Use

1. Your Blog Space Settings

1. Upload the SyntaxHighlighter files on your weblog space.
  • dp.SyntaxHighlighter/Scripts
  • dp.SyntaxHighlighter/Styles

2. Add JavaScript and CSS to your weblog page.
<link type="text/css" rel="stylesheet" href="Styles/SyntaxHighlighter.css"></link>
<script language="javascript" src="Scripts/shCore.js"></script>
<script language="javascript" src="Scripts/shBrushCSharp.js"></script>
<script language="javascript">
window.onload = function() {
    dp.SyntaxHighlighter.ClipboardSwf = 'Scripts/clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
};
 </script>

shCore.js is necessary. You can add only other shBrush{language name}.js that needed.

2. Windows Live Writer Settings

  1. Install the SyntaxHighlighter for Windows Live Writer plugin.
  2. Update weblog style. You can update style from menu "Weblog"-"Edit Weblog Settings..." and "Editing" tab.

3. How to Insert Code

  1. You can insert code from sidebar or menubar.

Last edited Dec 18 2008 at 11:25 PM by jz5, version 12

Want to leave feedback?
Please use Discussions or Reviews instead.

Downloads

--------------------ㅓ

표시되는 이미지  :

--------------------ㅓ

1 2  3  4  5  6

1번 버튼 누르면 1번 이미지가 나오고 2번 누름 2번 이미지가 나옴

버튼을 누르지 않을시에는 1번부터~6번까지 이미지가 돌아가면서 뿌려준다

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

setInterval Method

iTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])

clearInterval Method

window.clearInterval(iIntervalID)

iIntervalID Required. Integer that specifies the interval to cancel. This value must have been previously returned by the setInterval method.

위에 이 두함수만 알면 됨

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style3 {font-size: 18px; font-weight: bold; font-family: Verdana; }
-->
</style>
<script>
function showImg(img){
//changeImage 이미지 아이디
myimage=document.getElementById("changeImage")
myLink = document.getElementById("goUrl")
  if(img==0){
   myimage.src="0.jpg"
   myLink.href="http://www.naver.com";

  }else if(img==1){
   myimage.src="1.jpg"
   myLink.href="http://www.naver.com";
  }else if(img==2){
   myimage.src="2.jpg"
   myLink.href="http://www.naver.com";
  }else if(img==3){
   myimage.src="3.jpg"
   myLink.href="http://www.naver.com";
  }else if(img==4){
   myimage.src="4.jpg"
   myLink.href="http://www.naver.com";
  }else{
   myimage.src="5.jpg"
   myLink.href="http://www.naver.com";
  }
}
function stopReload(){
  window.clearInterval(timer)

}
var imageNumber=0;
var timer;
function startReload(){
timer=window.setInterval("refrashImage()", 3000);
//setTimeout("refrashImage()",1000);
}
function refrashImage(){
  if(imageNumber >6 ){
  imageNumber=0;
  }else{
   showImg(imageNumber)
   imageNumber = eval(imageNumber) + 1
  }
}
</script>
</head>

<body onload="startReload()">
<table width="49%" height="178" border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td height="138" colspan="6"><a  id="goUrl" href="http://www.naver.com"><img src="1.jpg" name="changeImage" width="470" height="300" id="changeImage" onmouseover="stopReload();" onmouseout="startReload();" /></a></td>
  </tr>
  <tr>
    <td height="38"><div align="center" class="style3"><a href="http://www.daum.net"><img src="mb_no1_over.gif" width="24" height="12" border="0" onmouseover="showImg(0);stopReload();" onmouseout="startReload();" /></a></div></td>
    <td><div align="center" class="style3" ><a href="http://www.yahoo.co.kr"><img src="mb_no2_over.gif" width="24" height="12" border="0" onmouseover="showImg(1);stopReload();" onmouseout="startReload();" / ></a></div></td>
    <td><div align="center" class="style3" ><a href="http://www.yahoo.co.kr"><img src="mb_no3_over.gif" width="24" height="12" border="0" onmouseover="showImg(2);stopReload();" onmouseout="startReload();" /></a></div></td>
    <td><div align="center" class="style3" ><a href="http://www.yahoo.co.kr"><img src="mb_no4_over.gif" width="24" height="12" border="0" onmouseover="showImg(3);stopReload();" onmouseout="startReload();" /></a></div></td>
    <td><div align="center" class="style3" ><a href="http://www.yahoo.co.kr"><img src="mb_no5_over.gif" width="24" height="12" border="0" onmouseover="showImg(4);stopReload();" onmouseout="startReload();" /></a></div></td>
    <td><div align="center" class="style3" ><a href="http://www.yahoo.co.kr"><img src="mb_no6_over.gif" width="24" height="12" border="0" onmouseover="showImg(5);stopReload();" onmouseout="startReload();" /></a></div></td>
  </tr>
</table>
</body>
</html>


Free Code

We have posted here and on FreeVBCode.com various Visual Basic and C#.NET code samples to help fellow developers.

Sample Add-In
Rijndael AES Block Cipher
MD5 Digest - VB, VBScript (ASP), and JavaScript versions
SHA-256 Digest - VB and VBScript (ASP)versions
FrezCrypto
ZLib Wrapper
String Sort
Path Routines
Domain Search
Create and Validate License Keys
Replacement for VBs SaveSetting and GetSetting
Custom Message Box - Replacement for VBs MsgBox Function

You may not redistribute any of the following free code as 'sample' or 'demos'. However, you are free to use the source code or components in your own code, but you may not claim that you created any of the sample code or compiled components found on this site. It is also expressly forbidden to sell or profit from any of the sample code or compiled components other than by the knowledge gained or the enhanced value added by your own code.

If you use any of the source code or compiled components on this site, you realize that you do so at your own risk. The code and components provided here are supplied as is without warranty or guarantee of any kind.

Should you wish to commission some derivative work based on the code provided here, or any consultancy work, please do not hesitate to contact us; sales@frez.co.uk

You can send bug reports, enhancement requests, or just general comments to phil.fresle@frez.co.uk


Sample Add-In VBAddInDemo.zip (25KB)

This sample Add-In demonstrates how to write an Add-In for Visual Basic 6.0. It provides some of the functionality you will find in our VBCodeHelper product that can be found at http://www.vbcodehelper.com.


Rijndael AES Block Cipher (VB Version) rijndaelvb.zip (13KB) (Updated 19-Apr-2001)

The zip file contains two implementations of the Rijndael AES Block Cipher based on the C code version published by Mike Scott. One is a VB 6.0 Class, the other a VBScript ASP version, both come with some test code that shows how to use them. Updated 03-Apr-2001 with two new methods and demo code that shows how to encrypt/decrypt strings. Updated 19-Apr-2001 to fix bug with 256 bit keys.


MD5 Digest - VB, VBScript (ASP), and JavaScript versions MD5.zip (17KB)

The zip file contains both VB6 and ASP (VBScript) versions of code for generating an MD5 'digest' or 'signature' of a string. In addition, a JavaScript version has now been included thanks to Enrico Mosanghini. The MD5 algorithm is one of the industry standard methods for generating digital signatures. It is generically known as a digest, digital signature, one-way encryption, hash or checksum algorithm. A common use for MD5 is for password encryption as it is one-way in nature, that does not mean that your passwords are not free from a dictionary attack.


Rijndael AES Block Cipher (C#.NET Version) rijndaelcs.zip (374KB) (Updated 13-Jul-2005)

The zip file contains a C# implementation of the Rijndael AES Block Cipher based on the C code version published by Mike Scott.


MD5 Digest - VB, VBScript (ASP), and JavaScript versions MD5.zip (17KB)

The zip file contains both VB6 and ASP (VBScript) versions of code for generating an MD5 'digest' or 'signature' of a string. In addition, a JavaScript version has now been included thanks to Enrico Mosanghini. The MD5 algorithm is one of the industry standard methods for generating digital signatures. It is generically known as a digest, digital signature, one-way encryption, hash or checksum algorithm. A common use for MD5 is for password encryption as it is one-way in nature, that does not mean that your passwords are not free from a dictionary attack.


SHA-256 Digest - VB and VBScript (ASP) versions SHA.zip (14KB)

The zip file contains both VB6 and ASP (VBScript) versions of code for generating a SHA-256 'digest' or 'signature' of a string. The SHA-256 algorithm is one of the industry standard methods for generating digital signatures. It is generically known as a digest, digital signature, one-way encryption, hash or checksum algorithm. A common use for SHA-256 is for password encryption as it is one-way in nature, that does not mean that your passwords are not free from a dictionary attack.


FrezCrypto FrezCrypto.zip (Version 1.2 - 18KB)

FrezCrypto is an ActiveX DLL component that wraps the Microsoft CryptoAPI and provides the user with methods to encrypt or decrypt strings. The user has the option of Block (RC2) or Stream (RC4) encryption. The encrypted data can be returned (or supplied for decryption) either as a string (complete with all manner of control characters) or converted to a hex format where each character is converted to the hex of its ascii value. The download contains the DLL, the Visual Basic code for the DLL, and some Visual Basic code that exercises the methods and shows how it maybe used.

Follow this link for a FAQ on FrezCrypto


Zlib Wrapper ZLibWrapper.zip (31KB)

Zlib Wrapper is a Visual Basic module and test harness that wraps the Zlib DLL as provided at the following web site; http://www.gzip.org/zlib/
The Zlib library is free and available for a number of different platforms, it provides a lossless compression routine and is useful for large strings containing duplicate data to some extent, for instance XML documents.


String Sort StringSort.zip (Version 1.1 - 5KB)

The string sort routines are contained in a Visual Basic module. The module includes algorithms for Quick Sort, Merge Sort, Insert Sort and Selection Sort. However, it is recommended that you use Quick Sort all the time as this 'non-standard' routine delegates to Insert Sort for small arrays and chunks.


Path Routines PathRoutines.zip (5KB)

Routines for path manipulation using the shlwapi.dll type library that comes with Internet Explorer. Comes complete with test harness.

GetRelativePath demonstrates when given a directory path and a file path how to return the relative path from the directory to the file.

GetCompactPath demonstartes how to compact a long path name down into a small space in order to display it effectively in, say, a small text box.


DomainSearch DomainSearch.zip (8KB)

An application that will do a smart search of the INTERNIC and NOMINET registrars for available .COM and .CO.UK domain names. The code could easily be extended to search other domains.


Create and Validate License Keys Registration.zip (19KB) (Version 2 - 27-May-2001)

The included classes and test form demonstrate three different methods on how you can generate license keys (such as the CD keys on the case of most Microsoft software) and test their validity for your applications.

Method 1: A 17 character numeric key. Simple technique, but could be guessed using a brute force attack.

Method 2: Generates a 25 character alpha-numeric key, the first 9 characters are completely random, the next 16 are based on an MD5 digest of the first 9 random characters plus an application specific string. 35,184,372,088,832 different possible keys for an application, extremely difficult to crack or guess.

Method 3: Generates a 16 character alpha-numeric key based on an MD5 digest of a supplied registered user name and an application specific string. Generates a key that is extremely difficult to crack where you know the name of the registered user.


Replacement for VB's SaveSetting and GetSetting RegSettings.zip (3KB)

This module contains two procedures; SaveStringSetting and GetStringSetting. These procedures can be used as replacements for VB's SaveSetting and GetSetting so that your data is written to the more useful 'HKEY_LOCAL_MACHINE\SOFTWARE' rather than the 'HKEY_CURRENT_USER\Software\VB and VBA Program Settings' key.


Custom Message Box - Replacement for VB's MsgBox Function CustomMB.zip (14KB)

This is a replacement for VB's standard MsgBox so that you can have a message box that is in the same style as the rest of your application (i.e. font size, colour, button size). It has an identical interface to VB's own MsgBox and so can be easily integrated into existing applications.

It also allows you to have non-standard message boxes by defining your own captions for buttons. There is an example that demonstrates displaying errors and including a 'Copy' button that copies the text to the clipboard so the user can paste the message into an email or document. 

 

New ASP.NET Charting Control: <asp:chart runat="server"/>

 데모다운받기
http://archive.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=4418

New ASP.NET Charting Control: <asp:chart runat="server"/>

Microsoft recently released a cool new ASP.NET server control - <asp:chart /> - that can be used for free with ASP.NET 3.5 to enable rich browser-based charting scenarios:

Once installed the <asp:chart/> control shows up under the "Data" tab on the Toolbox, and can be easily declared on any ASP.NET page as a standard server control:

<asp:chart /> supports a rich assortment of chart options - including pie, area, range, point, circular, accumulation, data distribution, ajax interactive, doughnut, and more.  You can statically declare chart data within the control declaration, or alternatively use data-binding to populate it dynamically.  At runtime the server control generates an image (for example a .PNG file) that is referenced from the client HTML of the page using a <img/> element output by the <asp:chart/> control.  The server control supports the ability to cache the chart image, as well as save it on disk for persistent scenarios.  It does not require any other server software to be installed, and will work with any standard ASP.NET page.

To get a sense of how to use the <asp:chart /> control I recommend downloading the Microsoft Chart Controls Sample Project.  This includes over 200 ASP.NET sample pages that you can run locally.  Just open the web project in VS 2008 and hit run to see them in action - you can then open the .aspx source of each to see how they are implemented.

The below example (under Chart Types->Line Charts->3D Line and Curve Charts) demonstrates how to perform Line, Spline and StepLine charting:

The below example (under Chart Types->Pie and Doughnut Charts) demonstrates a variety of pie and 3D doughnut options:

The below example (under Chart Types->Advanced Financial Charts) demonstrates some graph charts:

In addition to the above samples, you can download the Microsoft Chart Control Documentation or ask questions on the Chart Controls Forum to learn more.

This should provide a useful (and free) addition to your standard ASP.NET toolkit of functionality, and enable you to easily add richer visualization and data workflow scenarios to your ASP.NET applications.

Hope this helps,

Scott

Published Monday, November 24, 2008 10:38 PM by ScottGu

+ Recent posts