Пример #1
0
        /// <summary>
        /// Copy file from SharePoint
        /// </summary>
        /// <param name="url"></param>
        /// <param name="filePath"></param>

        public static void CopyFromSharePoint(
            string url,
            string filePath)
        {
            try
            {
                ClientContext context = GetClientContext(url);

                Uri              uri = new Uri(url);
                string           serverRelativeUrl = uri.PathAndQuery;
                FileInformation  info = File.OpenBinaryDirect(context, serverRelativeUrl);
                System.IO.Stream sr   = info.Stream;

                IO.FileStream sw         = new IO.FileStream(filePath, IO.FileMode.Create, IO.FileAccess.Write);
                int           Length     = 65536;
                Byte[]        buffer     = new Byte[Length];
                int           bytesRead  = sr.Read(buffer, 0, Length);
                long          totalBytes = 0;
                while (bytesRead > 0)
                {
                    sw.Write(buffer, 0, bytesRead);
                    totalBytes += bytesRead;
                    bytesRead   = sr.Read(buffer, 0, Length);
                }

                sr.Close();
                sw.Close();
                return;
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Пример #2
0
            internal override void Write(System.IO.Stream ostream)
            {
                string str = this.data.Length + ":";

                ostream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(str), 0, str.Length);
                ostream.Write(this.data, 0, this.data.Length);
            }
Пример #3
0
            internal override void Write(System.IO.Stream ostream)
            {
                string str = "i" + this.ToString() + "e";

                ostream.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(str), 0, str.Length);
            }