Dear all readers!

Our programming topics will moved to GEEKSSHIP.COMGEEKSSHIP.COM is a new developer community for Vietnamese Developers and developers from all over the world. It supports multiple  languages and can store all edited versions of a topic. GEEKSSHIP.COM is really a new generation of developer community.

 

Thưa tất cả bạn đọc!

Tất cả các bài viết về chủ đề lập trình SFI.VN Team sẽ chuyển sang website GEEKSHIP.COM. GEEKSSHIP.COM là một thế hệ cộng đồng dành cho lập trình viên mới cho Việt Nam và các lập trình viên trên toàn thế giới. GEEKSSHIP.COM hỗ trợ đã ngôn ngữ và nó sẽ lưu tất cả các phiên bản của một chủ đề để có thể tham khảo ngược. GEEKSSHIP.COM thực sự là điểm đến mới của cộng đồng lập trình viên!

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

I'm writing a asp.net mvc website that presents PPT file, so I use ZohoShow as storage and Zoho Show Viewer as a presenter.

 Zoho Show API to upload a ppt/pps file.

My code:

  1. public static void Upload(string username, string password, string apiKey, string filePath)   
  2.        {   
  3.            var ticket = GetTicket(username, password);   
  4.            if (string.IsNullOrEmpty(ticket)) return;   
  5.   
  6.            var requestUrl = "http://show.zoho.com/api/private/xml/uploadpresentation?apikey=" +    
  7.                apiKey + "&ticket=" + ticket;   
  8.   
  9.            var request = (HttpWebRequest)WebRequest.Create(requestUrl);   
  10.            request.Method = "POST";   
  11.            //request.Headers = new WebHeaderCollection();   
  12.            //request.Headers.Add("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-shockwave-flash, */*");    
  13.            string boundary = "-----------------------------" + DateTime.Now.Ticks.ToString("x");   
  14.            //string boundary = "------" + Guid.NewGuid().ToString().Replace("-", "");   
  15.            request.ContentType = "multipart/form-data; boundary=" + boundary;   
  16.            request.KeepAlive = true;   
  17.            request.Credentials =CredentialCache.DefaultCredentials;   
  18.   
  19.   
  20.            var postDataStream = new MemoryStream();   
  21.            const string newLine = "\r\n";   
  22.            var streamWriter = new StreamWriter(postDataStream);   
  23.            streamWriter.Write(boundary + newLine);   
  24.            streamWriter.Write("Content-Disposition: form-data; name=\"content\"; filename=\"" + (new FileInfo(filePath)).Name + "\"" + newLine);   
  25.            streamWriter.Write("Content-Type: application/vnd.ms-powerpoint"+ newLine + newLine);   
  26.            streamWriter.Flush();   
  27.   
  28.            var fileContent = (new FileInfo(filePath)).OpenText().ReadToEnd();   
  29.            streamWriter.Write(fileContent);   
  30.            streamWriter.Write(newLine);   
  31.            streamWriter.Write(boundary+newLine);   
  32.            streamWriter.Flush();   
  33.   
  34.            streamWriter.Write("Content-Disposition: form-data; name=\"submit\"" + newLine + newLine);   
  35.            streamWriter.Write("importpresentation" + newLine);   
  36.            streamWriter.Write(boundary+ "--" + newLine);   
  37.            streamWriter.Flush();   
  38.   
  39.            request.ContentLength = postDataStream.Length;   
  40.            using(var requestStream = request.GetRequestStream())   
  41.            {   
  42.                postDataStream.WriteTo(requestStream);   
  43.            }   
  44.   
  45.            streamWriter.Close();   
  46.            postDataStream.Close();   
  47.            //var content = new StringBuilder();   
  48.            //content.AppendLine(boundary);   
  49.            //content.AppendLine("Content-Disposition: form-data; name=\"content\"; filename=\"" + (new FileInfo(filePath)).Name + "\"");   
  50.            //content.AppendLine("Content-Type: application/vnd.ms-powerpoint");   
  51.            //content.AppendLine("");   
  52.            //var fileContent = (new FileInfo(filePath)).OpenText().ReadToEnd();   
  53.            //content.AppendLine(fileContent);   
  54.            //content.AppendLine(boundary);   
  55.            //content.AppendLine("Content-Disposition: form-data; name=\"submit\"");   
  56.            //content.AppendLine("");   
  57.            //content.AppendLine("importpresentation");   
  58.            //content.AppendLine(boundary + "--");   
  59.            //Console.WriteLine(content);   
  60.            //File.WriteAllText(@"e:\a.txt", content.ToString());   
  61.            //byte[] data = ASCIIEncoding.UTF8.GetBytes(content.ToString());   
  62.            //request.ContentLength = data.Length;   
  63.   
  64.            //var requestStream = request.GetRequestStream();   
  65.            //requestStream.Write(data, 0, data.Length);   
  66.            //requestStream.Close();   
  67.   
  68.            var response = request.GetResponse();   
  69.            // Get the stream containing content returned by the server.   
  70.            var responseStream = response.GetResponseStream();   
  71.            // Open the stream using a StreamReader for easy access.   
  72.            var reader = new StreamReader(responseStream);   
  73.            // Read the content.   
  74.            var responseFromServer = reader.ReadToEnd();   
  75.            Console.WriteLine(responseFromServer);   
  76.            // Display the content.   
  77.            ///ViewData["content"] = responseFromServer;   
  78.            //Console.WriteLine(responseFromServer);   
  79.            // Clean up the streams.   
  80.            reader.Close();   
  81.            responseStream.Close();   
  82.            response.Close();   
  83.        }  

 

But no matter how i try, Zoho Show server always refuse the request:System.Net.WebException: The remote server returned an error: (500) Internal Server Error.

If there is anybody interested with HttpWebRequest and ZohoShow, please give me some hint to make it works.

Thanks!

 

kick it on DotNetKicks.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: .NET , ASP.NET  Tags:
lehoangdung posted on February 12, 2010 15:31

Well, it's time to dance with VS2010 RC. I've used VS2010 Beta 2, but I didn't happy too much because It was really slow. In this RC version, everything seems changing, on Scottgu's blog, he add some comments from audience:

  • @DanWahlin: The performance improvements with Visual Studio 2010 RC compared to previous builds are huge. Really happy with what I'm seeing so far.
  • @peterbromberg: VS2010 RC: I must admit, I am impressed. Major speed and performance improvements. They are obvious immediately!
  • @Nick_Craver: RC performance is ridiculously faster, can't wait to switch over full time!
  • @Rlz2cool: Just tried VS2010 RC. One word incredible. Super fast, great build with things I saw in earlier releases fixed. So awesome.
  • @ddotterer: Trying out VS2010 RC: Snappier UI, much faster intellisense, significant build time reduction, etc. Overall: AWESOME JOB
  • @tomkirbygreen: Oh my goodness, VS2010 RC is much, much faster. Kudos to the VS perf team and everyone else. Uninstalling Visual Studio 2008 :-)
  • @JoshODBrown The developers on the Visual Studio 2010 RC must have had their usual beverages replaced with unicorn tears or something. #VS2010 #awesome
  • @jbristowe: Holy Butterball! VS 2010 RC is crazy fast. It makes me feel like this: http://bit.ly/cPaOvE
Voila, they said that, but we must try to know is VS 2010 RC good enough. 

I'm installing it...

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: .NET , ASP.NET , ASP.NET MVC  Tags:
lukepro posted on December 4, 2009 19:10

 

RESAPER :

ReSharper cung cấp giải pháp:

Hiển thị  toàn bộ  lỗi và được tô sáng

Loại bỏ mã dư thừa

Đưa ra giải pháp tức thì  cho các lỗi tìm thấy , phân tích giá trị ,đưa ra khung chú thích

Tính năng hiệu chỉnh code làm cho code gọn gàng và dễ nhìn = phím nóng Ctrl+ K+D

Hỗ trợ  công cụ test ,chạy thử nghiệm và gỡ rối

Chuyển hướng tiện dụng như goto  và tính năng tìm kiếm nhanh lẹ như:

Xác định vị trí trong Solution Explorer,xem lại nhưng tìm kiếm gần đây

và rất nhiều hữu ích khác

Download: http://www.jetbrains.com/resharper/download/index.html

 

 

Jquery intellisense Dành Cho vs 2008:

Các bước cài đặt :

B1: Cài đặt thêm VS 2008 SP1 vào cho bản VS 2008(nghĩa là bạn phải có VS2008 trước)

DownLoad :http://msdn.microsoft.com/en-us/vstudio/cc533448.aspx

B2: Cài đặt VS 2008 Patch KB958502 để hổ trợ "-vsdoc.js" Intellisense Files

Download: http://code.msdn.microsoft.com/KB958502/Release/ProjectReleases.aspx?ReleaseId=1736

B3:Download file jQuery-vsdoc.js

DownLoad :http://docs.jquery.com/Downloading_jQuery#Download_jQuery

 

Cách sử dụng :

Cái thả jquery-1.3.2-vsdoc.js vào

 

 

 

 

 

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: .NET , ASP.NET , Visual Studio , JQuery  Tags:
lehoangdung posted on November 21, 2009 00:07

I mapped a table to NHibernate (which's id is Indentity type), and write a repository method using NHibernate.LinQ as below:

 

And the code listing below is test unit:

 

And error when testing:

 

But when I use Expression:

 

Every thing is ok, test unit run correctly! I don't know why? If anyone know how to fix it, please help!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

lehoangdung posted on November 20, 2009 19:08

Today I will introduce a tool for Visual Studio Build Version Increment Add-In Visual Studio

I want to have automatic build version increment for my apps and libraries to avoid setting it manually again and again. After 5 minutes searching on the internetnet, I found Build Version Increment add-in for Visual Studio 2005/2008. This add-in is very simple in use but do exactly what everyone developer needs. 

You can download it here: Build Version Increment Add-In Visual Studio

 

*Example of using this tool:

After you installed the addin, fire off Visual Studio and open your favorite solution. Your tools menu should contain an entry for the increment settings.


Clicking on this will display a dialog containing a mini solution explorer. Here you can select the solution or one of the available projects and change it's auto versioning properties:


The property grid contains the following values you can modify:

  • Versioning Style. Here you can configure per version attribute the increment scheme you wish to use. Options are:
    • None: Don't update this attribute.
    • Increment: Simple +1 increment per build.
    • TimeStamp: Set the attribute to the current time. (HHMM)
    • YearStamp: Set the attribute to the current year. (YYYY)
    • DeltaBaseDate: Use the Yogesh increment scheme for this attribute.
    • YearDayOfYear: Set the attribute to the current year followed by the day of the year. (YYDDD)
    • DeltaBaseYearDayOfYear: Set the attribute to the delta base year including day of year. (YYDDD)
    • DeltaBaseYear: Set the attribute to the delta base year.
  • Update file version. Setting this to true will update the AssemblyFileVersion attribute.
  • Update assembly version. Setting this to true will update the AssemblyVersion attribute.
  • Assembly info filename. If your project or solution isn't using the default AssemblyInfo.(cs|vb|cpp) file to set the assembly attributes, you can specify it here. Note that the path is stored relative so this also works for other project members.
  • Configuration name. Set this to the configuration name (Debug, Release, ...) which should be active.
  • Start date. Set this to a custom start date if you're using one of the delta versioning types.

 


Whenever one of the projects in the solution is beeing build, the addin kicks in and updates the required attributes. If the target file containing the attributes is under source control the addin will check it out.

*Result of the above setting:

 

 

I love this addin! :)

If you feel happy with this post, please kick it! 

 

kick it on DotNetKicks.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

lequangthai posted on November 17, 2009 08:10

Bài viết này mình đọc được tại blog Suprotim Agarwal,thầy hay hay nên viết lại. Bài viết nói về việc kết hợp giữa việc ứng dụng RepeaterControl của ASP.NET và LinQ.

Mình có một Repeater Control mà mỗi dòng của nó là một radio button,mỗi dòng đó sẽ được gán với các bộ dữ liệu với nhiều cột dữ liệu,tất nhiên một trong số đó có cột Id và không thể biểu diễn giá trị cột đó trên View.Vấn đề là làm thế nào để xác định được Id của bộ dữ liệu được chọn? Một trong các cách là ta có thể sử dụng LinQ.

Chúng ta sẽ thử làm một ví dụ để biểu diễn việc này,để bắt đầu,hãy mở Visual Studio 2008,chọn File -> New -> Web -> ASP.NET Web Application.Tại đây chúng ta chủ yếu viết code trên 2 file default.aspx và default.aspx.cs

Đầu tiên,chúng ta sẽ tạo lớp People để làm cấu trúc data trong ví dụ của chúng ta.

Vì đây là ví dụ nên chúng ta sẽ tạo lớp trên trong default.aspx.cs cho tiện.

Trong class People ở trên ta sẽ sử dụng thuộc tính UniqueId làm Id cho people và tất nhiên,thuộc tính này sẽ không được hiển thị lên View. Tiếp theo,chúng ta sẽ add repeater control vào trang default.aspx.Code hoàn chỉnh:

Ở trên ta thấy có function SetUniqueRadioButton bằng javascript,sử dụng hàm này nhằm giới hạn người dùng tại một thời điểm chỉ chọn một nút radio button(một bộ dữ liệu).Thông thường,hệ thống radio button sẽ hoạt động tốt khi đặt trong cùng một GroupName (tức là tại mỗi thời điểm chỉ có thể chọn một radio button),nhưng repeater sẽ làm "hỏng" GroupName này khi được trả về trình duyệt.

Cài đặt đoạn code này vào default.aspx.cs để đảm bảo chỉ có thể chọn 1 radio button tại một thời điểm.

Tạo data để test:

tiếp theo ta sẽ viết code cho Button1_Click để tìm ra dòng dữ liệu mà ta đã được chọn,tại đây ta sẽ sử dụng LinQ

Để xác định radio button nào được chọn,mình sẽ sử dụng từ khóa "let" của LinQ, nó sẽ tạo ra một biến tạm và chỉ có câu lệnh LinQ sử dụng.

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: .NET , ASP.NET Webforms , LinQ  Tags:
lehoangdung posted on November 14, 2009 18:45

In my portal project, I save the bitmap file into SQL Server as a byte array, so to convert the byte array from SQL Server to bitmap, I must implement some function, this is some ways I found on the internet:

Method 1: Unsafe methods, using Marshal class

 

Method 2: Using a memory stream (I like this way)

 

Please kick it if you feel interested! :)

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: .NET , GDI+, DirectX  Tags:

Page List

    Calendar

    «  September 2010  »
    MoTuWeThFrSaSu
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910
    View posts in large calendar

    Recent Comments

    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010 SFI.VN Team