by
Hanno
6. January 2012 12:33
Sometimes when sending an email with attachments, we want to (re)move the attachments when the sending is complete. The problem that might arise is that the file somehow magically is still in use by some or other process.
The guilty party most likely is the MailMessage object (if it isn't, then this post won't help you
) that you just created.
To resolve the issue you need to dispose the handles from the mail message to the files. I have written a method that does this for us.
private void ReleaseEmailAttachmentFileHandles(MailMessage msg)
{
foreach (Attachment attachment in msg.Attachments)
{
attachment.Dispose();
}
msg.Attachments.Dispose();
}
by
Hanno
7. December 2011 10:45
Problem
I am creating a WPF application that consumes a WCF web service. I ran into a problem with accessing the web service through a proxy on some machines, with the error details being "The remote server returned an unexpected response: (407) Proxy Access Denied." or "The remote server returned an error: (407) Proxy Authentication Required.".
Solution
The solutions turned out to be that you are required to set the WebRequest object's default web proxy credentials (WebRequest.DefaultWebProxy.Credentials) by using the following statement:
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
Make sure that you have no proxy settings in your app.config file as, according to this article, "The DefaultWebProxy property reads proxy settings from the app.config file. If there is no config file [or no settings in the config file], the current user's Internet Explorer (IE) proxy settings are used."
Sample
- Create a new console application project
- Add the service reference
- Add the following code to your application:
ComServiceClient svc = new ComServiceClient();
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
Console.WriteLine(svc.CheckStatus());
Console.ReadLine();
- The resulting program looks as follows:
using System;
using System.Net;
using WebServiceTester.ServiceReference1;
namespace WebServiceTester
{
class Program
{
static void Main(string[] args)
{
ComServiceClient svc = new ComServiceClient();
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
Console.WriteLine(svc.CheckStatus());
Console.ReadLine();
}
}
}
Additional Reading
12274c32-99cd-458e-b824-07041e848fdf|0|.0
Tags:
by
Hanno
18. November 2011 10:01
To get the application startup path you can use the following code:
AppDomain.CurrentDomain.BaseDirectory
by
Hanno
24. June 2011 06:41
I recently had some trouble figuring out the smtp server when using my CellC 3G connection. The resources on the web (none on CellC's website) didn't help. Sven's post pointed me in the right direction, although smtp.cmobile.co.za is not correct.
The correct smtp server for CellC is: mail.cmobile.co.za
by
Hanno
12. April 2011 21:44
Robocopy is a Microsoft product that ships standard with Windows Vista, Windows 7 and Windows Server 2008. It is also available in the Windows Resource Kit, since Windows NT 4.0. The version I used was for Windows Server 2003 and I got it here.
Robocopy is short for "Robust Copy". It's usage is explained on this page from Microsoft. It has many great features and is definitely worth checking out.
An example implementation that I use it for is to make a copy of a folder, plus all it's subfolders and files. I then proceeded to create a batch script that I could schedule in the task scheduler of the server, and have it execute at specified intervals. The command line switches I used basically tells robocopy to copy all new or changed files from the source directory, but it will not delete any files that are in the destination folder but not in the source folder.
I have thus been able to "create" a scheduled archiving utility with robocopy.
As a side note, I discovered robocopy whilst looking for a solution for copying files with long path names.
d55fd11b-476f-4525-b879-fbc316091503|0|.0
Tags:
by
Hanno
4. April 2011 21:41
I've never had a situation where I could not drag and drop in Windows when I wanted to copy some files from one location to another. Recently though, my perfect world was troubled when I ran into a problem with exceptionally long filenames (I refer to the total length of the file's location, i.e. c:\temp\dir1\dir2\dir3\dir4\dir5\file1.txt). Turns out that there is a limitation on the maximum length of the filename in the Windows API. You can find a very interesting post about it here.
To get around this I thought I'd use xcopy, which is included in most Windows releases. Whilst providing some neat advanced functionality, it did not solve the problem and I constantly got a "Insufficient Memory" exception. This basically just means that my path names were still too long.
So after some further consultation with Dr. Google©, I came accross an alternative from Microsoft©, namely Robocopy. Researching this utility revealed that it might solve my problem, but I wasn't sure, and skipped it in favor of a newer "better" utility from Microsoft.
Enter RichCopy, which as it turns out also doesn't solve my problem. RichCopy though, has an easy to use interface which basically utilises the robocopy library from Microsoft.
I was able to find a workaround my problem, but it is not ideal at all, and will fail as soon as the path length increases again.
Basically what I did was to create mapped drives to local folders using the UNC naming convention. I then proceeded to copy the files from one mapped drive to the next. I used the RichCopy GUI to copy files as it makes it quite easy to select specific folders and conditions for copying them.
Thanks to Joshua Hoffman and CS Truter.
EDIT: It turns out that Robocopy works like a charm! I also ran into some issues with RichCopy crashing for no apparent reason...
by
Hanno
30. March 2011 08:27
If you ever require a Windows Update, but just can't seem to find it with a search engine, try this link. You can pretty much find any update here! You have to use IE though, and you will have to install an ActiveX component as well.
Thanks to http://blogs.msdn.com/b/ukcrm/archive/2010/11/18/downloading-crm-2011-updates.aspx and CS Truter
f39edd20-989b-4600-92a9-b13b25ca3a94|0|.0
Tags:
by
Hanno
4. March 2011 07:17
When you try to open a company in Pastel Partner, you might be faced with a message telling you that you cannot open the company as a backup is in progress.
I recently developed a web application that was to integrate with a client's Pastel Partner database, and I could not read any data because of the "backup in progress" error. I figured that somewhere there was a flag being set that would indicate that the current company's is being backed up.
NOTE: I had received a backup copy of the Pastel Partner data from the client, which they had obviously made whilst a backup was in progress.
There was basically two possible places where such a flag could be set, 1) in the database, and 2) in a folder somewhere. Now I couldn't really get into the database as Pastel Partner uses Pervasive as a storage engine, so I figured I'd give the folders options a bash.
It didn't take me long to spot a file named "backup.txt" that resides in the root of the company folder. Once I deleted this file, I was able to open a company inside Pastel Partner.
WARNING: I would not recommend deleting the "backup.txt" file from the company folder on a live system, as this might interrupt the backup process, or corrupt the backup set (I have not tested this, as the backups completed too quickly on my machine).
by
Hanno
11. January 2011 21:08
I have been putting off upgrading my blog to the latest version, partly due to some concerns about the amount of time it might take, and also I wasn't really looking forward to the hassles that one usually (not always, but Murphy's Law(s) apply to me) encounters with an upgrade of a website and database. Surprisingly though, this upgrade went rather smoothly, and also did not take very long.
The upgrade instructions can be found here. One thing I had a bit of an issue with, was with images and files that I have previously uploaded/embedded in posts. There is a folder named files under the App_Data folder that needs to be copied to your new installation as well.
I had some minor customizations on some user controls that I easliy migrated with the help of Notepad++'s Compare functionality.
Back to the blogging-sphere!!!
f39780a9-695e-4e4c-ba22-bf651f880759|0|.0
Tags:
by
Hanno
15. December 2010 09:27
Remote Desktop is a pretty cool and effective tool to use.
I've recently had a few occasions where the following scenario played out:
Assume we have a website that we have deployed to a server. We need to make changes to one of the HTML pages of the site. The only way we can publish the site is to copy the files accross via remote desktop. The following steps typically indicate the process followed:
- Edit the file in question and save
- Copy the file
- Paste the file on the remote computer
Steps 1 to 3 can be repeated multiple times, depending on how quickly you resolve the issue that you have.
One thing to note is that your filename will typically remain the same. So this is where I believe there is a "caching" issue with remote dektop, when copying the same file (note: the file contents have changed, but the file name remains the same) accross multiple times, that the original version of the file kept in cache somewhere and is pasted on the remote computer. This means that your changes effectively do not get copied over, so you might end up spending a lot of time on trying to figure out why your changes aren't reflecting on the remote system although you have made certain that you have made these changes.
To get around this, I have set up my archiving utility (I pretty much always compress my files before copying them accross) to append a time stamp to the filename of the archive, which basically makes the filename that I copy accross unique. This ensures that you copy a "new" file every time.
Happy Remoting!