public string UploadManagedFile(string username, string password, string fileName, string contentType, byte[] fileContent)
        {
            Authenticate(username, password);
            string result = string.Empty;
            DownloadFile downloadFile = new DownloadFile();
            downloadFile.FileName = fileName;
            downloadFile.ContentType = contentType;
            DataProvider.Instance.UploadFileMetadata(downloadFile);

            // Now write the content away
            if (fileContent != null) {
                string serverPath = downloadFile.ServerFilePath;
                if (!Directory.Exists(Path.GetDirectoryName(serverPath))) {
                    Directory.CreateDirectory(Path.GetDirectoryName(serverPath));
                }
                using (FileStream fileStream = new FileStream(serverPath, FileMode.Create)) {
                    fileStream.Write(fileContent, 0, fileContent.Length);
                }

                result = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
                result += "/DownloadFile.ashx?FileID=" + downloadFile.FileID;
            }

            return result;
        }
Ejemplo n.º 2
0
 public void UploadFileMetadata(DownloadFile downloadFile)
 {
     downloadFile.FileID = Convert.ToInt32(Helper.ExecuteScalar(
         Helper.CreateCommand("[TrialBalanceDownloadServer].[UploadFileMetadata]",
             Helper.CreateParameter("@FileName", downloadFile.FileName),
             Helper.CreateParameter("@ContentType", downloadFile.ContentType))));
 }