Skip to content

Instantly share code, notes, and snippets.

View Yecats's full-sized avatar

Stacey Haffner Yecats

View GitHub Profile
@Yecats
Yecats / WeekIn.NET.20160718.md
Created July 11, 2016 17:21
Tips for the Week in .NET

Please comment below...

@Yecats
Yecats / linqtosqlsnippet.cs
Created July 12, 2016 16:47
7/11/16 Package of the Week - Code Snippet
var twitterCtx = new TwitterContext(...);
var searchResponse =
await
(from search in twitterCtx.Search
where search.Type == SearchType.Search &&
search.Query == "\"LINQ to Twitter\""
select search)
.SingleOrDefaultAsync();
@Yecats
Yecats / WeekIn.NET.20160725.md
Created July 18, 2016 16:43
Tips for the Week in .NET

Please comment below...

@Yecats
Yecats / imageresizerexample.cs
Created July 18, 2016 16:44
ImageResizer Example
//Loop through each uploaded file
foreach (string fileKey in HttpContext.Current.Request.Files.Keys)
{
HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
if (file.ContentLength <= 0) continue; //Skip unused file controls.
//The resizing settings can specify any of 30 commands.
//Destination paths can have variables like <guid> and <ext>, or
//even a santizied version of the original filename, like <filename:A-Za-z0-9>
ImageResizer.ImageJob i = new ImageResizer.ImageJob(file, "~/uploads/<guid>.<ext>", new ImageResizer.ResizeSettings(
@Yecats
Yecats / WeekIn.NET.20160802.md
Created July 25, 2016 16:45
Tips for the Week in .NET

Please comment below...

@Yecats
Yecats / openpopnet.cs
Created July 26, 2016 15:51
OpenPop.NET Example
public static List<Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
{
// The client disconnects from the server when being disposed
using(Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(hostname, port, useSsl);
// Authenticate ourselves towards the server
client.Authenticate(username, password);
@Yecats
Yecats / longpathsample1.cs
Created August 2, 2016 16:34
Long Path Support Sample 1
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version=".NETFramework,Version=v4.6.2"/>
</startup>
</configuration>
@Yecats
Yecats / longpathsample2.cs
Created August 2, 2016 16:35
Long Path Sample 2
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version=".NETFramework,Version=v4.5.2"/>
</startup>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false" />
</runtime>
</configuration>
@Yecats
Yecats / dataannotationsample1.cs
Created August 2, 2016 16:39
DataAnnotation Sample 1
public class ContactInfo
{
[Required(ErrorMessage = "Your email address is invalid")]
[Display(Name = "User Email")]
public int Email { get; set; }
[Required(ErrorMessage = "Your phone number is invalid")]
[Display(Name = "User Phone")]
public int Phone { get; set; }
}
@Yecats
Yecats / dataannotationoldsample1.cs
Created August 2, 2016 16:46
Data Annotation - Old Sample
public class User
{
[Required(ErrorMessageResourceType = typeof(ModelResources),
ErrorMessageResourceName = "FirstName_Required")]
[StringLength(50, ErrorMessageResourceType = typeof(ModelResources),
ErrorMessageResourceName = "FirstName_StringLength")]
public sstring FirstName { get; set; }
[Required(ErrorMessageResourceType = typeof(ModelResources),
ErrorMessageResourceName = "LastName_Required")]