Via this post.
I created a column in a certain table to contain various files with "VarBinary(MAX)" as its data type.
I wanted to test stuff, so I needed data in the tables.
But Oh My, Now What? Should I really write C# Project to insert a file?
Well, no, not needed, you can do it directly from SQL.
Create Table EmployeeProfile
(
EmpId int,
EmpName varchar(50) not null,
EmpPhoto varbinary(max) not null
)
Go
Insert EmployeeProfile (EmpId, EmpName, EmpPhoto)
Select 1001, 'Vadivel',
BulkColumn from Openrowset( Bulk 'C:\Blue Lace 16.bmp', Single_Blob) as EmployeePicture
Via this post.
Following is a quick way to execute code and limiting it within a certain timeout.
Note that the code spawns a new thread.
A better safer code would be using the ThreadPool and wait on the WaitHandle.
Thread t = new Thread(
() =>
{
//Do Stuff Here
});
t.Start();
bool success = t.Join(TimeSpan.FromSeconds(10));
if (success)
{
//Thread completed successfully
}
else
{
throw new TimeoutException();
}
Internet Explorer 6 has problems displaying a PNG image with alpha transparency.
Follow the instructions detailed in this post to solve the issue.
Note that you should apply width & height for every image you apply the style to. (At least from my experience)
I can't believe I wasted 10minutes on something that should be the simplest ever.
You might encounter an exception when trying to host a WCF service in IIS with windows authentication where it would say the IIS isn't configured with windows auth so the service itself can't be configured with windows auth.
I had that exception.
The problem is that the IIS vdir was configured with windows auth! and it still blew up.
After a quick searching, I found this post which did the trick.
So.. if you do encounter this, I hope I saved you some time.
Via this post.
The post discusses the issue of using LINQ-to-SQL with dynamic mappings.
The problem
You have SQL Servers for each of your environments (development, test, pre-prod, production) and in each one, the table names are different. In fact, it’s not the table names that are different but the schema names but since the schema name is part of the table name, it must be specified.
Ex : dev.ZeTable et prod.ZeTable
Easy to solve, right? Just put the schema value in the config file and do a simple concatenation at runtime. Well, it’s not as easy as it seams because the table name is stored in an attribute of the partial class generated by the LINQ to SQL designer and Microsoft didn’t provide a way or method to change it at runtime.
[Table(Name="dev.ZeTable")]
public partial class TheTable
Solution
The solution is to dynamically load at runtime a mapping specific for each environment.
Here’s how to do it:. (Go to the post..)
If you're trying to host a WCF service with a .svc extension and you get a 404 response or get plain text, it means your IIS had not been configured with the .svc extension.
Follow this post instructions.
Via Stefan's post.
Wonderful News! You can enable intellisense in blend
You need to install a plug-in and there's a few gotcha's so do read Stefan's post for all the details.
A great discovery :)
There is a non-so-familiar way to apply trimming to text in HTML using simple CSS.
In order to apply a certain width on an element and together ensure that its innerText will be bound to that and will be trimmed accordingly, we can do the following:
<span class="LongTextContainer">Very long text here.. Bla Bla Bla</span>
.LongTextContainer
{
width: 300px;
position: fixed;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
The text-overflow determines that the text will be trimmed while showing ellipsis in the end.
This seems to do the trick quite perfect.
Read additional information in this post.
In one of my projects I was working on building a smart router facade using WCF.
The general idea -
The consumer will have an actual endpoint to the router.
The router intercepts the client messages, performs all sort of necessary operations and processing, then sends the message to the actual service.
This is called a "smart" router since it's not playing the part as a simple pass-through router.
It actually provides service virtualization, interception of messages and passing it along to the appropriate endpoint, taking into mind Management, Monitoring and Governance. A sort of ESB.
The idea was to support most configurations and profiles of common services all around.
The project was not trivial to write. Plus, it's pretty far from being truly 100% complete.
I will write a series of posts illustrating the key points I had encountered throughout the project, there were quite many.
For the meantime, a good place to start would be reading the following articles by Michele Leroux Bustamante -
Building a WCF Router, Part 1
Building a WCF Router, Part 2
A nice way to convert text to title-case using the .NET framework.
Title Case - First Letter Of Every Word Is Upper
CultureInfo.CurrentCulture.TextInfo.ToTitleCase("some text"); //Returns "Some Text"
Note that you should ensure the input passed to the method is all in lower case, otherwise you will encounter scenarios where this would not work.
Via this post.
Following mime types should be registered in ISS, when using VSTO and ClickOnce:
.application
application/x-ms-application
.manifest
application/x-ms-manifest
.deploy
application/octet-stream
.deploy
application/x-ms-vsto
Very simple piece of code to get the path where the executing assembly is located.
private
static string GetApplicationPath()
{
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
The CTP version of Velocity had been released a while back.
It certainly has great benefits.
Here's a link to Bart's post going over this release, worths the check.
From Bart's post:
Introduction
But first... what's in a name? Multi-tiered distributed applications are common-sense nowadays and with cloud computing within reach the need to build scalable distributed services has never been bigger. One of the core aspects in enabling those scenarios is to have intelligent caching of objects, not only to reduce the number of accesses to the underlying data source but also to boost availability by employing scale out techniques. Obviously, developers want to be able to do all of this without having to worry about the complexities that this brings, having to deal with load balancing and availability themselves. That's where Velocity comes into play.
The core idea is very straightforward: we have a cache that behind the scenes is distributed and replicated across a bunch of machines called the cluster. Storing data in the distributed cache is as easy as calling some Add or Put method, and retrieving it is as easy as calling Get. With some creative stealing from the documentation we end up with the following picture:
An important thing to emphasize is the fact the cache clients deal with regular .NET objects all the time and don't have to worry about storing those objects. Indeed, .NET serialization takes care of the rest. There are more concepts to it such as cache eviction policies (when objects are removed from the cache, such as least-recently used or LRU), the distribution mechanism where simple clients just contact the cluster "in the cloud" through any cache host and get redirected to whatever host the object is available on versus routing clients that have awareness of object placement through a routing table. Other important pieces include the supported concurrency models and associated locking mechanisms but let's not go there in this introductory post.
Almost every project I write has a configuration file and its content varies from one environment to another.
In this case, managing multiple configuration files can make life a lot easier.
There are different approaches for doing this, I'll link to a demonstration made by Scott Hanselman a while back - Click Here.
In short:
1 - Create configuration builds.
2 - Add a batch file at the root of the project as written below.
3 - Add a Pre-Build action to execute it.
The batch file 'copyifnewer.bat' content:
@echo off
echo Comparing two files: %1 with %2
if not exist %1 goto File1NotFound
if not exist %2 goto File2NotFound
fc %1 %2
if %ERRORLEVEL%==0 GOTO NoCopy
echo Files are not the same. Copying %1 over %2
copy %1 %2 /y & goto END
:NoCopy
echo Files are the same. Did nothing
goto END
:File1NotFound
echo %1 not found.
goto END
:File2NotFound
copy %1 %2 /y
goto END
:END
echo Done.
The pre-build action to be inserted:
"$(ProjectDir)copyifnewer.bat" "$(ProjectDir)web.config.$(ConfigurationName)" "$(ProjectDir)web.config"
I implemented a Security Token Service in WCF as part of our WS-Trust solution here in our project.
I needed a certificate to apply the message security and all that WS-Federation requires.
I needed to set it up quickly for a temporary purpose, thus I created a certificate using 'makecert.exe' (accessible through VS2008 Command Prompt).
One of the valid set of arguments to create a certificate for such use is:
makecert.exe -sr LocalMachine -ss My -a sha1 -n CN=WCFCert2 -sky exchange -pe
You can change the store name / location and certificate name as you like.
I'll end by saying that using such certificates in production is not recomended.
The best thing to do is to get a chain-trusted certificate for your STS and services.
One additional thing - in order to add a certificate to the trusted people store execute the following:
certmgr.exe -add -r LocalMachine -s My -c -n localhost -r CurrentUser -s TrustedPeople
Next page »