dipl0
dipl0

Reputation: 1077

Accessing Sharepoint File and FileType Using C#

I am currently adapting existing c# and trying to identify filetype from when a file is uploaded. The following

    public override void ItemAdded(SPItemEventProperties properties)
    {
        commentscheck(properties);
    }

The commentscheck function that is called from this function is attempting to verify what filetype something is.

I was wondering whether I could access something from SPItemEventProperties that would be able to tell me the filetype that has been uploaded?

Upvotes: 0

Views: 65

Answers (1)

Mike
Mike

Reputation: 807

Check the properties.AfterUrl and split it.

public override void ItemAdded(SPItemEventProperties properties)
{
    string[] FileTypeParts = properties.AfterUrl.Split(".");
    string fileType = FileTypeParts [FileTypeParts .length-1];
    string FileNameParts = properties.AfterUrl.Split("/");
    string FileName = FileNameParts [FileNameParts .length-1];
    commentscheck(properties);
}

Upvotes: 1

Related Questions