Ok going of what i talked about in my last post about the name changing from the http:// syntax to the \\ UNC syntax. i will post the code that i wrote to accomplish this inside of our office add-in.
The big problem with office, is that it gives you back the filename as a URL like http://
it needs to be in the UNC format like \\.
this is specific to excel, just replace wrkbk.FullName with the filename string.
if ((wrkbk.FullName.StartsWith("http://"))&&(wrkbk.FullName.Contains("workspace.office.live")))
{
string temp = wrkbk.FullName.Substring(7);
string toReturn = "\\\\" + temp;
toReturn = toReturn.Replace("/", "\\");
toReturn = toReturn.Replace(".com\\", ".com\\DavWWWRoot\\");
return toReturn;
}
Also, in our code we determine the file type, we use this later when we grab the file.
public enum FilenameType:byte
{
/// <summary>
/// The file is accessed using a c:\dir\filename.
/// </summary>
drive = 0x01,
/// <summary>
/// The file is accessed using a \\server\share\filename.
/// </summary>
unc = 0x02,
/// <summary>
/// The file is accessed using http:filename or ftp:filename.
/// </summary>
url = 0x04,
/// <summary>
/// The filename is null or 0 length.
/// </summary>
none = 0x10,
/// <summary>
/// Is inside a jar or zip file.
/// </summary>
zip = 0x20,
/// <summary>
/// Is inside the Office 2007 template file.
/// </summary>
self = 0x40,
/// <summary>
/// The filename uses some other mechanism.
/// </summary>
other = 0x80
} ;
if it is a URL we use this
case FilenameType.url:
WebRequest req = WebRequest.Create(filename);
WebResponse resp = req.GetResponse();
return resp.GetResponseStream();
otherwise we use this
default:
return new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Now just to ensure that we pick the right filetype for office live documents, which we need to treat differently than a standard http:// file i have this code
if (filename.Contains("workspace.office.live"))
return FilenameType.unc;
if (filename.StartsWith("http:") || filename.StartsWith("ftp:") || filename.StartsWith("file:"))
return FilenameType.url;
This is where we stand right now, it works properly and we are able to download and save to the workspace. Now hopefully microsoft isnt going to change any of this, or if they do, they will document it.
if there are any questions please post a comment.
Comments