C# WebClient FileDownLoad 에러 해결



using System;
using System.ComponentModel;
using System.Net;
 
namespace WebClient_FileDownLoad
{
   class ClientDownLoadFile
   {
      static void Main( string[] args )
      {
         // 서버측에서 알 수 없는 헤더 Agent로 인해서 정상적인 파일다운 불가
         WebClient webClient = new WebClient();
         webClient.DownloadFileCompleted += new AsyncCompletedEventHandler( FileDownLoadCompleted );
 
         // 익스플로러의 헤더 에이전트 추가해서 문제 해결
         webClient.Headers.Add( "User-Agent",
            "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.3; WOW64; Trident/7.0)" );
 
         string sUrl = "파일 다운로드 주소";
 
         webClient.DownloadFileAsync( new Uri( sUrl ), "다운파일 이름" );
 
         Console.ReadLine();
      }
 
      static void FileDownLoadCompleted( object sender, AsyncCompletedEventArgs e )
      {
         Console.WriteLine( "DownLoad Finished...." );
      }
   }
}




Posted by seanpaul
,


MicroSoft Visual Studio 사용 할 때 좋은 확장 도구(Add-in)



1. MicroSoft Productivity Power Tools



2. CodeMaid ( http://www.codemaid.net/ )


설치 후에 Cleaning - Progressing - 체크를 모두 해제.



3. Visual Assist (  https://goo.gl/9Zf4bS )


4. 더 많은 확장 도구들

https://visualstudiogallery.msdn.microsoft.com/



Posted by seanpaul
,


Highlight.JS 티스토리 사용 하기


1. https://highlightjs.org/  Get version 버전 - 버튼 클릭( 작성시 버전 8.6 )


2. CDN을 사용해서 전체 스크립트를 사용 할 수도 있고 필요한 언어만 사용하는

커스텀 팩으로 설치 할 수도 있다.


3. 이 글에서는 Custom Package를 이용함. Download 버튼을 눌러서 파일 저장


4. 다운로드한 Highlight.zip을 적당한 곳에 풀고


5. highlight.pack.js와 원하는 색상의 하이라이터 CSS 파일을 티스토리에 업로드

   ( styles 폴더의 monokai_sublime.css 선택 )


6. skin.html의 <Head> </Head> 사이에 아래 코드 추가


  <script src="./images/highlight.pack.js"></script>

  <script>hljs.initHighlightingOnLoad();</script>


7. sytle.css의 body { } 아래 코드 추가 ( 글자 크기와 폰트는 원하는 것으로 수정 )


pre code {

  font: normal 13pt consolas;

}


코드 사용 방법 ( 글 작성시 HTML 사용 체크 )


  <pre><code class="적용 언어"> 코드 </pre></code> 



아래 예제는 c# 적용 ( 다른 언어는 html, javascript, java, xml 등등 )


<pre><code class="csharp">

using System.IO;


namespace FileSystem

{

    public interface IFileSystem

    {

        string ReadAllText( string filename );

    }

    public class FileSystem : IFileSystem

    {

        public string ReadAllText( string filename )

        {

            return File.ReadAllText( filename );

        }

    }

    public static class FileHelper

    {

        public static bool IsEmpty( IFileSystem fs, string f )

        {

            var content = fs.ReadAllText( f );

            return string.IsNullOrEmpty( content );

        }

    }

</pre></code>


적용 결과

using System.IO;

namespace FileSystem
{
    public interface IFileSystem
    {
        string ReadAllText( string filename );
    }
    public class FileSystem : IFileSystem
    {
        public string ReadAllText( string filename )
        {
            return File.ReadAllText( filename );
        }
    }
    public static class FileHelper
    {
        public static bool IsEmpty( IFileSystem fs, string f )
        {
            var content = fs.ReadAllText( f );
            return string.IsNullOrEmpty( content );
        }
    }
} 



Posted by seanpaul
,
URL:




URL:


Wait. Loading....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<script type="text/javascript">
function makeShort()
{
   var longUrl=document.getElementById("longurl").value;
    var request = gapi.client.urlshortener.url.insert({
      'resource': {
      'longUrl': longUrl
    }
    });
    request.execute(function(response)
    {
  
        if(response.id != null)
        {
            str ="<b>Long URL:</b>"+longUrl+"<br />";
            str +="<b>Short URL:</b> <a href='"+response.id+"'>"+response.id+"</a><br />";
            document.getElementById("output").innerHTML = str;
        }
        else
        {
            alert("error: creating short url n"+ response.error);
        }
  
    });
 }
  
function getShortInfo()
{
var shortUrl=document.getElementById("shorturl").value;
  
    var request = gapi.client.urlshortener.url.get({
      'shortUrl': shortUrl,
    'projection':'FULL'
    });
    request.execute(function(response)
    {
  
        if(response.longUrl!= null)
        {
            str ="<b>Long URL:</b>"+response.longUrl+"<br />";
            str +="<b>Create On:</b>"+response.created+"<br />";
            str +="<b>Short URL Clicks:</b>"+response.analytics.allTime.shortUrlClicks+"<br />";
            str +="<b>Long URL Clicks:</b>"+response.analytics.allTime.longUrlClicks+"<br />";
  
            document.getElementById("output").innerHTML = str;
        }
        else
        {
            alert("error: "+response.error);
        }
  
    });
  
}
function load()
{
    //Get your own Browser API Key from  https://code.google.com/apis/console/
    gapi.client.setApiKey('AIzaSyD0Gwt6ptEKHCVSCUehjFhpbJG_v0IwQPY');
    gapi.client.load('urlshortener', 'v1',function(){document.getElementById("output").innerHTML="";});
  
}
window.onload = load;
  
</script>
<script src="https://apis.google.com/js/client.js"> </script>
  
 
  
URL: <input type="text" id="longurl" name="url" value="http://www.daum.net"> <br><br>
<input type="button" value="Create Short" onclick="makeShort();"> <br> <br><br>
  
URL: <input type="text" id="shorturl" name="url" value="http://goo.gl/p8CK"> <br><br>
<input type="button" value="Get Short  URL Info" onclick="getShortInfo();"><br>
  
<div id="output">Wait. Loading....</div>
Posted by seanpaul
,

C# 구글 ShortURL

C# 2014. 6. 24. 05:01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
 
namespace Google_Short_URL
{
    class ShortURL
    {
        static void Main( string[] args )
        {
            // 티스토리 에디터에서 <id> 부분을 HTML 태그로 인식해서
            // 자동으로 </id> 태그 붙임.
 
            // 정규식 으로 반환된 짧은 URL 캡쳐
            const string MATCH_PATTERN = @"""id"": ?""(?<id>.+)""";
 
            //var httpWebRequest = (HttpWebRequest)WebRequest.Create( "https://www.googleapis.com/urlshortener/v1/url" );
            WebRequest httpWebRequest = WebRequest.Create( "https://www.googleapis.com/urlshortener/v1/url" );
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";
 
            using (StreamWriter streamWriter = new StreamWriter( httpWebRequest.GetRequestStream() ))
            {
                string myUrl = "https://developers.google.com/url-shortener/v1/getting_started?hl=ko";
                //string json = "{\"longUrl\":\"http://www.google.com/\"}";
 
                string json = "{\"longUrl\":\"" + myUrl + "\"}";
 
                // 긴 URL 출력
                Console.WriteLine( "긴 URL : {0}\n", json );
                streamWriter.Write( json );
            }
 
            //var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            WebResponse httpResponse = httpWebRequest.GetResponse();
            using (StreamReader streamReader = new StreamReader( httpResponse.GetResponseStream() ))
            {
                var responseText = streamReader.ReadToEnd();
                Console.WriteLine("{0}\n", responseText );
                Console.WriteLine( "반환된 짧은 URL : {0}\n",
                    Regex.Match( responseText, MATCH_PATTERN ).Groups["id"].Value );
            }
        }
    }
}
// 티스토리게시판 태그 에러
</id>
Posted by seanpaul
,

테스트 스크립트

C# 2014. 6. 23. 13:44
사용자 함수 사용방법 

더할때(더할때는 더하기 기호를 생략 해도 됨) 
UDF_Column_Hidden_Sum(합산범위,"+") 

곱할때 
UDF_Column_Hidden_Sum(곱합범위, "*")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Function UDF_Column_Hidden_Sum(rngWrk As Range, Optional Oper As String = "+")
    Dim strTemp As String
    For Each c In rngWrk
        If c.EntireColumn.Hidden = True Then
        Else
            If c.Columns = 1 Then
                strTemp = c.Value
            Else
                strTemp = strTemp & Oper & c.Value
            End If
        End If
    Next
    UDF_Column_Hidden_Sum = Evaluate(strTemp)
End Function



1
Test Plain Text
Posted by seanpaul
,