Pregunta

I am tring to use a method or function to create the directory tree that I need, and return the new path to the calling procedure.

But I cannot get it to compile

I get an error cannot convert method group 'localAttachmentsPath' to non delegate type string ..

here is my code - what have I done wrong? And is there a better way to accomplish this?

        private string localAttachmentsPath(ref string emailAttachmentsPath)
        {

            string sYear = DateTime.Today.Year.ToString();
            string sMonth = DateTime.Now.ToString("MMMM");
            string sDirectoryDate = DateTime.Today.ToString("dd.MM.yyyy");

            if (!Directory.Exists(emailAttachmentsPath))
            {
                Directory.CreateDirectory(emailAttachmentsPath);

            }

            emailAttachmentsPath = emailAttachmentsPath + "\\" + sYear;
            if (!Directory.Exists(emailAttachmentsPath))
            {
                Directory.CreateDirectory(emailAttachmentsPath);
            }

            emailAttachmentsPath = emailAttachmentsPath + "\\" + sMonth;
            if (!Directory.Exists(emailAttachmentsPath))
            {
                Directory.CreateDirectory(emailAttachmentsPath);
            }

            emailAttachmentsPath = emailAttachmentsPath + "\\" + sDirectoryDate;
            if (!Directory.Exists(emailAttachmentsPath))
            {
                Directory.CreateDirectory(emailAttachmentsPath);
            }

            //localAttachmentsPath = emailAttachmentsPath;
            return localAttachmentsPath;

        }
¿Fue útil?

Solución

You can make your return type as void and remove return statement as you are passing variable emailAttachmentsPath as reference variable so it wouldbe updated from the caller without return statement.

Your Method should look like:

private void localAttachmentsPath(ref string emailAttachmentsPath)
{

//your code

//no return statement

}

Otros consejos

You need to simply specify the value you want to return, like this:

return emailAttachmentsPath;

I would also recommend you drop the ref keywordfrom the parameter.

Further Reading

It looks like the problem is this:

return localAttachmentsPath;

That is a function, I think you want to declare a local variable with some other name than the function name.

If you are using ref string emailAttachmentsPath than you do not need to return any string

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top