Monday, January 16, 2012

How to create the file SharePoint portal through code

In a scenario, I have to write the code that creates and validates the Http path existence and create the file in that path.

There are some classes in System.IO i.e. (FileInfo, FileStream) that are used to work with the file stystem, but those API doesn’t provide support for the http protocol, so to perform that specific task, I converted the http path into shared path with the help of the System.Url class with some logic.
public static FilePath convertsToAbsolutePath(FilePath _url)


    System.Uri  uri;
    FilePath    filePath;
    FilePath    absolutePath;
    Name        hostName;
        uri          = new System.Uri(_url);
        absolutePath = uri.get_AbsolutePath();
        hostName     = uri.get_Host();

        // converts the http path into Abosolute path
        filePath = strFmt(@'\\%1%2', hostName, strReplace(absolutePath, '/' , '\\'));
    checkFailed("http path is either not valid path or convertable");

    return filePath;

No comments:

Post a Comment