Recently I received some questions about the IE language setting that affects the MOSS search results. It seems the MOSS (like ASP.NET 2.0 application) has taken advantage of the CultureInfo class to directly convert the client browser's user-language setting( [lang]-[region] such as en-us, zh-cn) to a CultureInfo instance. Sammy Jankis has provided a blog entry explaining on this:
#How To: Avoid IE language settings affecting MOSS search results
http://blogs.microsoft.co.il/blogs/adir_ron/archive/2007/12/11/how-to-avoid-ie-language-settings-affecting-moss-search-results.aspx
As Introducted in previous entry, the Microsoft Online technical forum support team is building a code sample framework including many useful code that cover most of the development technologies of Microsoft. You can get the All-In-One Code Framework at the following site:
http://cfx.codeplex.com
Also, for Chinese users, there is a dedicated localized project for it:
http://cfxchs.codeplex.com
In addition, to provide better user experience and guide on the sample code, there will publish kb articles associated with some of the samples in the code framework:
http://support.microsoft.com/search/default.aspx?query=kbcodefx
Just enjoy it!
I've seen many guys confused about the .NET app.config file for the exe application and the dll assembly(we can see Visual Studio generate app.config file for both of exe and dll project). Here is a good article discussing on this:
#App.config in C# with VS2005 - Part II: DLL within an EXE
http://juststuffreally.blogspot.com/2008/02/appconfig-in-c-with-vs2005-part-ii-dll.html
Eli Robillard has given a good blog entry introducing the WSS/MOSS ULS log which is important for sharepoint troubleshooting:
#SharePoint Trace Logs and the Unified Logging Service (ULS)
http://weblogs.asp.net/erobillard/archive/2008/07/31/sharepoint-trace-logs-and-the-unified-logging-service-uls.aspx
Also, there is code sample in MSDN about how to write custom provider that helps write custom messages into ULS log:
#Trace Log Example
http://msdn.microsoft.com/en-us/library/aa979522.aspx
#Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 1 of 2)
http://msdn.microsoft.com/en-us/library/bb530302(printer).aspx
#Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 2 of 2)
http://msdn.microsoft.com/en-us/library/bb530301(printer).aspx
Here is a blog entry from Wenlong Dong's blog which explains the "ASP.NET Compatibility Mode" in WCF:
#ASP.NET Compatibility Mode
http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx
John has posted a good blog entry describing how to make vhd image work between VPC/Virtual server and the new windows server 2008 hyper-v based virtualization solution.
#Are VHDs compatible between Hyper-V and Virtual Server and Virtual PC?
http://blogs.technet.com/jhoward/archive/2008/02/28/are-vhds-compatible-between-hyper-v-and-virtual-server-and-virtual-pc.aspx
[ASP.NET]How to implement file upload and download in ASP.NET MVC
File upload/download is very useful functionality in web application. Here is a simple implementation of file upload/download in ASP.NET MVC 1.0. The sample use a “FileManager” controller to handle file download and file upload requests. And for download, I created a custom ActionResult class to stream out the binary file content.
FileManager Controller
|
namespace MVCFileWeb.Controllers
{
/// <summary>
/// MVC Controller class for file upload and download
/// </summary>
public class FileManagerController : Controller
{
/// <summary>
/// default Action
/// </summary>
public ActionResult Index()
{
var files = from f in System.IO.Directory.GetFiles(
Server.MapPath("~/App_Data/download/"),
"*.*",
SearchOption.TopDirectoryOnly)
select System.IO.Path.GetFileName(f);
return View(files.ToList());
}
/// <summary>
/// action for file download
/// </summary>
public ActionResult Download(string fn)
{
string pfn = Server.MapPath("~/App_Data/download/" + fn);
if (!System.IO.File.Exists(pfn))
{
throw new ArgumentException("Invalid file name or file not exists!");
}
return new BinaryContentResult(){
FileName = fn,
ContentType="application/octet-stream",
Content= System.IO.File.ReadAllBytes(pfn)
};
}
/// <summary>
/// Action for file upload
/// </summary>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Upload()
{
string upload_dir = Server.MapPath("~/app_data/upload/");
foreach (string f in Request.Files.Keys)
{
if (Request.Files[f].ContentLength > 0)
Request.Files[f].SaveAs(upload_dir + System.IO.Path.GetFileName(Request.Files[f].FileName));
}
return RedirectToRoute(new { Action = "Index", Controller = "FileManager" });
}
}
} |
Custom ActionResult for file download(as binary stream):
|
namespace MVCFileWeb
{
public class BinaryContentResult: ActionResult
{
public BinaryContentResult()
{}
public string ContentType { get; set; }
public string FileName { get; set; }
public byte[] Content { get; set; }
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ClearContent();
context.HttpContext.Response.ContentType = ContentType;
context.HttpContext.Response.AddHeader("content-disposition",
"attachment; filename=" + FileName);
context.HttpContext.Response.BinaryWrite(Content);
context.HttpContext.Response.End();
}
}
} |
Index view of FileManager Controller:
|
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<List<String>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Files for download</h2>
<%foreach (string file in Model)
{%>
<br /><%= Html.ActionLink(file,"Download",new {Action="Download", fn=file}) %>
<%} %>
<hr />
<h2>Upload new file</h2>
<% using (Html.BeginForm("Upload", "FileManager", FormMethod.Post, new { enctype = "multipart/form-data" }))
{%>
<br />File1:<input type="file" name="file1" id="file1" />
<br />File2:<input type="file" name="file2" id="file2" />
<br /><input type="submit" value="submit" />
<% } %>
</asp:Content>
|
You can also get the complete solution in attachment.
Finally, ASP.NET MVC 1.0 comes to RTM. Anyone who're interested in ASP.NET MVC (and prefer non-beta installation) can get it here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b&displaylang=en
Enjoy it!
Here is a good MSDN tech article which demonstrate using custom MessageInspector to validate WCF xml message:
#How to: Perform Message Validation with Schema Validation in WCF
http://msdn.microsoft.com/en-us/library/cc949095.aspx
Some of my colleagues are building a code sample project on codeplex. I think it an very useful and interesting project which can help many community members who want to startup in a certain programming technology and look for some basic samples. Here is the introduction of this project:
All-In-One Code Framework(CodeFX)
Have you ever needed a quick understanding of a technique, e.g. ActiveX or VSX, but been daunted by the few or too many samples and documents that are available on the Internet? Have you ever downloaded or created a good sample, e.g. a named pipe sample for IPC, but forgotten where the sample was placed after a few days? Have you ever wanted a simple test environment, e.g. a COM object or a DLL, but become tired of frequently creating such projects and naming them as "ClassLibrary1", "ClassLibrary2", "ClassLibraryABC"?
If your answer is YES to any one of these questions, this All-In-One Code Framework will be of assistance to you.
I recently see this project in CodePlex. This project is a demonstration of most Microsoft development techniques, for example COM component, ADO.NET, Interop technology, DLL delay loading, .NET Framework, etc.
You can see the basic project architecture in the following diagram:
Examples for COM and ActiveX:
Examples for Library:
Examples for IPC and RPC:
Read some currently existing code samples, I am interesting of .NET implementation of ActiveX control(VBActiveX, CSActiveX), DLL delay loading, COM client hosting CLR, LINQ samples. It is appropriate for you to learn and understand the unfamiliar techniques, for example COM, IPC, etc. You can have a look at this project in http://cfx.codeplex.com/ to play with it. Enjoy it!
[WCF]Exposing WCF service to raw MSMQ client via msmqIntegrationBinding
WCF has provided two built-in bindings to help work with MSMQ. NetMsmqBinding and MsmqIntegrationBinding. NetMsmqBinding is good for client & services which are both built upon .NET 3.5 WCF component. While MsmqIntegrationBinding is good for communication between raw MSMQ and .NET WCF.
There is already a good example on how to communication with MSMQ based application(server) from a WCF based client.
#How to: Exchange Messages with WCF Endpoints and Message Queuing Applications
http://msdn.microsoft.com/en-us/library/ms789008.aspx
Here I’ve created a simple sample which demonstrate how to use raw MSMQ client(based on System.Messaging component) to communicate with WCF msmqIntegrationBinding based service. The solution consists of 4 projects:
l ClassLib that contains shared ServiceContract and DataContract definition
l WCF ServiceApp which contains the service host using msmqIntegrationBinding
l WCF clientApp which use WCF code to consume the service
l Raw MSMQ ClientApp which use System.Messaging component to consume the service
All the WCF code use programmatic approach instead of app.config to configure the service and client endpoints. Solution attached in “WCFMSMQSln.zip”