Esempio n. 1
0
        /// <summary>
        /// See if file can be opened for writing, return error if not
        /// </summary>
        /// <param name="path"></param>

        public static string CanWriteFile(
            string path)
        {
            try
            {
                if (!SharePointUtil.IsSharePointName(path))
                {
                    bool       exists = File.Exists(path);
                    FileStream fs     = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                    fs.Close();
                    if (!exists)                     // if didn't exist before then delete it
                    {
                        try { File.Delete(path); }
                        catch (Exception ex) { ex = ex; }
                    }
                }

                else
                {
                    return(SharePointUtil.CanWriteFile(path));
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("");
        }
Esempio n. 2
0
        /// <summary>
        /// See if file can be opened for reading, return error message if not
        /// </summary>
        /// <param name="path"></param>

        public static string CanReadFile(
            string path)
        {
            try
            {
                bool isNormalFilePath = (!SharePointUtil.IsSharePointName(path));

                if (isNormalFilePath)
                {
                    FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                    fs.Close();
                }

                else
                {
                    return(SharePointUtil.CanReadFile(path));
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("");
        }
Esempio n. 3
0
/// <summary>
/// Copy file including SharePoint support
/// </summary>
/// <param name="?"></param>

        public static void CopyFile(
            string sourceFileName,
            string destFileName)
        {
            if (!SharePointUtil.IsSharePointName(sourceFileName) &&
                !SharePointUtil.IsSharePointName(destFileName))
            {             // both regular files
                File.Copy(sourceFileName, destFileName, true);
            }

            else if (SharePointUtil.IsSharePointName(sourceFileName) &&
                     SharePointUtil.IsSharePointName(destFileName))
            {             // both SharePoint
                string tempFile = TempFile.GetTempFileName();
                SharePointUtil.CopyFromSharePoint(sourceFileName, tempFile);
                SharePointUtil.CopyToSharePoint(tempFile, destFileName);
                File.Delete(tempFile);
            }

            else if (SharePointUtil.IsSharePointName(sourceFileName))             // source only is SharePoint
            {
                SharePointUtil.CopyFromSharePoint(sourceFileName, destFileName);
            }

            else             // dest only is SharePoint
            {
                SharePointUtil.CopyToSharePoint(sourceFileName, destFileName);
            }

            return;
        }
Esempio n. 4
0
/// <summary>
/// Return true if file exists
/// </summary>
/// <param name="path"></param>
/// <returns></returns>

        public static bool Exists(
            string path)
        {
            if (!SharePointUtil.IsSharePointName(path))
            {
                if (File.Exists(path))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            else
            {
                if (Lex.IsNullOrEmpty(SharePointUtil.CanReadFile(path)))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// If SharePoint file create a local cached copy of the file that can be read directly
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>

        public static string CacheLocalCopyIfSharePointFile(string path)
        {
            if (!IsSharePointName(path))
            {
                return(path);
            }

            string ext      = IO.Path.GetExtension(path);        // use same extension
            string tempFile = TempFile.GetTempFileName(ext);

            SharePointUtil.CopyFromSharePoint(path, tempFile);
            return(tempFile);
        }
Esempio n. 6
0
/// <summary>
/// Get last write time for file
/// </summary>
/// <param name="path"></param>
/// <returns></returns>

        public static DateTime GetFileLastWriteTime(
            string path)
        {
            if (!SharePointUtil.IsSharePointName(path))
            {
                if (!File.Exists(path))
                {
                    return(DateTime.MinValue);
                }

                FileInfo fi = new FileInfo(path);
                return(fi.LastWriteTime);
            }

            else
            {
                return(SharePointUtil.GetFileUpdateDate(path));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Get length of file or -1 if doesn't exist
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>

        public static long GetFileLength(
            string path)
        {
            if (!SharePointUtil.IsSharePointName(path))
            {
                if (!File.Exists(path))
                {
                    return(-1);
                }

                FileInfo fi = new FileInfo(path);
                return(fi.Length);
            }

            else
            {
                throw new NotSupportedException(path);
            }
        }