Friday, September 11, 2009

URI Format Not Supported.

I am Sending a Mail with attachemts for this I have Made A WCF Which works fine when I give the Network path of the file. but I need to host It And when I try to give a URL path It Says. URI format not supported please Help My Code in WCF

public List funSendMail(Mailcls m)
        {
            List result = new List();
            try
            {
                /* Create a new blank MailMessage with the from and to adreesses*/
                System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(m.Sender, m.Receiver);
                /*Checking the condition that the cc is empty or not if not then
                 * include them
                 */
                if (m.Cc != null && m.Cc != string.Empty)
                {
                    mailMessage.CC.Add(m.Cc);
                }
                /*Checking the condition that the Bcc is empty or not if not then
                 * include them
                 */
                if (m.Bcc != null && m.Bcc != string.Empty)
                {
                    mailMessage.Bcc.Add(m.Bcc);
                }
                //Ading Subject to the Mail
                mailMessage.Subject = m.Subject;
                //Adding the Mail Body
                mailMessage.Body = m.Body;

                /* Set the properties of the MailMessage to the
                   values on the form as per the mail is HTML formatted */

                mailMessage.IsBodyHtml = true;


                /* Bigining of Attachment1 process   & 
                   Check the all file for a attachment */

                if ((m.AttachfilesPath != null) && (m.AttachfilesPath.Count > 0))
                {
                    foreach (string s in m.AttachfilesPath)
                    {
                        result.Add("Attaching File : " + s);
                       
                        System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(s);                        
                        /* Attach the newly created email attachment */
                        mailMessage.Attachments.Add(attach);
                    }

                }

                /* Set the SMTP server and send the email with attachment */
                System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
                // smtpClient.Host = emailServerInfo.MailServerIP;
                //this will be the host in case of gamil and it varies from the service provider
                smtpClient.Host = m.Host;
                //smtpClient.Port = Convert.ToInt32(emailServerInfo.MailServerPortNumber);
                //this will be the port in case of gamil for dotnet and it varies from the service provider
                smtpClient.Port = m.Port;
                smtpClient.UseDefaultCredentials = true;
                //smtpClient.Credentials = new System.Net.NetworkCredential(emailServerInfo.MailServerUserName, emailServerInfo.MailServerPassword);
                smtpClient.Credentials = new System.Net.NetworkCredential(m.UserName, m.Password);
                //this will be the true in case of gamil and it varies from the service provider
                smtpClient.EnableSsl = m.SSL;
                smtpClient.Send(mailMessage);

                try
                {

                    /* Delete the attachements if any */
                    foreach (string s in m.AttachfilesPath)
                    {
                        File.Delete(s);
                    }
                }
                catch { }
                result.Add("1");

            }
            catch (Exception ex)
            {
                result.Add("-2 " + ex.Message);
            }
            return result;

        }
and In Calling Appication (Which is a Silverlight Application)


ObservableCollection cv = new ObservableCollection();
            //cv.Add(@"\\C6\Shared\Repo\a\Drafts\go.png");//This Works
            cv.Add(@"www.msdotnetmentor.com/wp-content/uploads/2009/08/5.JPG");//This Doesnot Work
            Mail.Bcc = txtBCC.Text;
            Mail.Body = txtMailBody.Text;
            Mail.Cc = txtCC.Text;
            //Mail.AttachfilesPath = SendDraftAttachment;
            Mail.AttachfilesPath = cv;
            Mail.Host = EditDeleteEmailConfig.SMTPHost;
            Mail.Password = EditDeleteEmailConfig.SMTPPassword;
            Mail.Port = EditDeleteEmailConfig.SMTPPort;
            Mail.Receiver = txtTo.Text;
            Mail.Sender = txtFrom.Text;
            Mail.SSL = EditDeleteEmailConfig.SMTPSSL;
            Mail.Subject = txtSubject.Text;
            Mail.UserName = EditDeleteEmailConfig.SMTPUserName;
            SuccessMessage = "Mail Sent Successfully";
            ErrorMessage = "Error In Sending Mail" + Environment.NewLine + "Try Sending Later";
            if (EmailSettings)
            {
                SendClient.funSendMailAsync(Mail);
                SendClient.funSendMailCompleted += new EventHandler(SendClient_funSendMailCompleted);
            }
            else
            {
                EditDeleteEmailConfig = new EmailConfig();
                IsSendMail = true;
                EmailSettingsClient.GetEamilConfigByClientIdAsync(userID);
            }



Now The Solution IS


Fine I got The Answer

Points:
1. URI is not a physical path so it can't be used for File Handling as we need the Physical path for that.
2. There is nothing in WCf like server.mappath()
3. we have to do some workaround to achive so and that work around is

add the following Namespaces :
using System.ServiceModel.Activation;
using System.Web;


now the class implementing the intervfce or the WCF class Use This Line of Code
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]


Eg:
// NOTE: If you change the class name "SendMailWCF" here, you must also update the reference to "SendMailWCF" in App.config.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SendMailWCF : ISendMailWCF
{


and now you can access the file like
string RD = HttpContext.Current.Server.MapPath("Repo") + @"\" + filename;



And below is an excerpt from the web.config.



<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <behaviors> </behaviors> <services> </services>

Saturday, August 29, 2009

Scour Friend Invite

Hey,

Check out: http://scour.com/invite/meetu.choudhary/

I'm using a new search engine called Scour.com. It shows Google/Yahoo/MSN
results and user comments all on one page. Best of all we get rewarded for
using it by collecting points with every search, comment and vote. The
points are redeemable for Visa gift cards. Join through my invite link so we
can be friends and search socially!

I know you'll like it,
- MeetuChoudhary

This message was sent to you as a friend referral to join scour.com, please
feel free to review our http://scour.com/privacy page and our
http://scour.com/communityguidelines/antispam page.
If you prefer not to receive invitations from ANY scour members,
please click here - http://www.scour.com/unsub/e/bWVldHVjaG91ZGhhcnkubWVldEBibG9nZ2VyLmNvbQ==

Write to us at:
Scour, Inc., 15303 Ventura Blvd. Suite 220, Sherman Oaks, CA 91403, USA.

campaignid: scour200908290001
Scour.com

Saturday, August 22, 2009

Stop Searchprotocolhost.exe on WindowsXP

Searchprotocolhost.exe is one of the reason to make your system slow. Following are the step(s) to stop this and make system fast.

1. Click Start -> Run or Press Windows + R
2. Type services.msc and press 'Ok' or click 'Enter'
3. Scroll down to find 'Windows Search' and double click
4. Stop the process

Another step to disable it from Startup:
5. Reapeat step number 1
6. Type 'msconfig' and press 'Ok' or click 'Enter'
7. Click on 'Startup' tab
8. Uncheck 'Windows Search' checkbox
9. Click Ok.

Restart your system.

To verify :
Open your TaskManager by pressing 'Ctrl+Alt+Del' and locate for Searchprotocolhost.exe in process tab.

Thursday, August 20, 2009

Meetu At First Page of City Bhaskar, Jaipur

City Bhaskar, Jaipur Coverd The story of Meetu Choudhary of Becomming an MVP. Check The PDF here
and More Details Here..

Subscribe via email

Enter your email address:

Delivered by FeedBurner

MSDotnetMentor

MSDotnetMentor My Website http://msdotnetmentor.com