private void BindData(String sortDirection) { Logger mLog = Logger.Instance(); DataTable oTable = new DataTable("MyTable"); oTable.Columns.Add("COL1", Type.GetType("System.String")); oTable.Columns.Add("COL2", Type.GetType("System.String")); DataRow oRow = oTable.NewRow(); oRow = oTable.NewRow(); oRow["COL1"] = "Chapter(10)"; oRow["COL2"] = "Chapter(10)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Chapter 2 Ep 2-3"; oRow["COL2"] = "Chapter 2 Ep 2-3"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Chapter 2 Ep 1-2"; oRow["COL2"] = "Chapter 2 Ep 1-2"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = ""; oRow["COL2"] = ""; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Rocky(IV)"; oRow["COL2"] = "Rocky(IV)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Chapter(1)"; oRow["COL2"] = "Chapter(1)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Chapter(11)"; oRow["COL2"] = "Chapter(11)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Rocky(I)"; oRow["COL2"] = "Rocky(I)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Rocky(II)"; oRow["COL2"] = "Rocky(II)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Rocky(IX)"; oRow["COL2"] = "Rocky(IX)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Rocky(X)"; oRow["COL2"] = "Rocky(X)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Chapter(2)"; oRow["COL2"] = "Chapter(2)"; oTable.Rows.Add(oRow); oRow = oTable.NewRow(); oRow["COL1"] = "Chapter 1 Ep 2-3"; oRow["COL2"] = "Chapter 1 Ep 2-3"; oTable.Rows.Add(oRow); DataView myDV = oTable.DefaultView; Framework.Common.SortTable mySorter = new Framework.Common.SortTable(); String mColName = "COL1"; mySorter.Sort(oTable, mColName, sortDirection); StartTime.Text = mySorter.StartTime.ToString(); StopTime.Text = mySorter.StopTime.ToString(); TimeSpan ts = mySorter.StopTime.Subtract(mySorter.StartTime); mLog.Debug(ts.TotalMilliseconds.ToString()); lblTotalTime.Text = ts.TotalMilliseconds.ToString(); GridView2.DataSource = oTable; GridView2.DataBind(); DropDownList2.DataSource = oTable; DropDownList2.DataTextField = "COL1"; DropDownList2.DataBind(); string mySort = "COL1 " + sortDirection; myDV.Sort = mySort; DropDownList3.DataSource = myDV; DropDownList3.DataTextField = "COL1"; DropDownList3.DataBind(); GridView3.DataSource = myDV; GridView3.DataBind(); oTable.Dispose(); myDV.Dispose(); }
//http://osman.it/aspnet/jquery-ajax-file-upload/ public void ProcessRequest(HttpContext context) { string mResponse = "Success"; try { string mAction = GWWebHelper.GetQueryValue(context.Request, "Action"); string mCurrentDirectory = GWWebHelper.GetQueryValue(context.Request, "CurrentDirectory"); MFunctionProfile mFunctionProfile = FunctionUtility.GetProfile(mAction); MDirectoryProfile mDirectoryInfo = DirectoryUtility.GetProfileByFunction(mFunctionProfile.Id); string mDirectory = mDirectoryInfo.Directory; if (!string.IsNullOrEmpty(mCurrentDirectory)) { if (mDirectory.LastIndexOf(Path.DirectorySeparatorChar) != mDirectory.Length) { mDirectory += Path.DirectorySeparatorChar + mCurrentDirectory; } } string mUploadDirectory = ""; try { mUploadDirectory = context.Request.Files.AllKeys[0].ToString().Substring(0, context.Request.Files.AllKeys[0].LastIndexOf(".")); } catch (Exception) { mUploadDirectory = context.Request["fileName"].ToString(); mUploadDirectory = mUploadDirectory.Substring(0, mUploadDirectory.LastIndexOf(".")); mUploadDirectory = Path.DirectorySeparatorChar + mUploadDirectory; } if (!Directory.Exists(mUploadDirectory)) { FileUtility.CreateDirectory(mDirectory, mUploadDirectory, mDirectoryInfo); } mUploadDirectory = mDirectory + Path.DirectorySeparatorChar + mUploadDirectory; if (context.Request["completed"] == null) { if (mDirectoryInfo != null) { FileUtility.DoUpload(context.Request.Files.AllKeys[0], context.Request.Files[0], mUploadDirectory, mDirectoryInfo); if (context.Request["single"] != null) { string mFileName = context.Request.Files[0].FileName; string mNewpath = Path.Combine(mUploadDirectory, mFileName); FileUtility.RenameFile(mNewpath, mDirectory + mFileName, mDirectoryInfo); FileUtility.DeleteDirectory(mUploadDirectory, mDirectoryInfo); } } } else { if (context.Request["completed"].ToString().ToLowerInvariant() == "true") { string mFileName = context.Request["fileName"].ToString(); string mPath = mUploadDirectory; string mNewpath = Path.Combine(mPath, mFileName); char mDirectorySeparatorChar = Path.DirectorySeparatorChar; if (mDirectoryInfo != null) { DataTable mFileTable = FileUtility.GetDirectoryTableData(mUploadDirectory, mDirectoryInfo, true); SortTable mSorter = new Framework.Common.SortTable(); String mColName = "Name"; mSorter.Sort(mFileTable, mColName, "ASC"); DataView mFiles = mFileTable.DefaultView; mFiles.RowFilter = "Name like '" + mFileName.Substring(0, mFileName.Length - 4) + "%'"; foreach (DataRowView rowView in mFiles) { DataRow row = rowView.Row; string mPartialFileName = mUploadDirectory + mDirectorySeparatorChar.ToString() + row["Name"].ToString(); if (mPartialFileName.EndsWith("_UploadNumber_1")) { if (File.Exists(mNewpath)) { File.Delete(mNewpath); } } if (mPartialFileName != mNewpath) { mergeFiles(mNewpath, mPartialFileName); } } FileUtility.RenameFile(mNewpath, mDirectory + mFileName, mDirectoryInfo); FileUtility.DeleteDirectory(mUploadDirectory, mDirectoryInfo); } } } } catch (Exception ex) { Logger mLog = Logger.Instance(); mLog.Error(ex); mResponse = "Error"; } context.Response.ContentType = "text/plain"; context.Response.Write(mResponse); }
/// <summary> /// Returns a table of files and/or directories. /// </summary> /// <param name="path">string</param> /// <param name="directoryProfile">MDirectoryProfile</param> /// <param name="filesOnly">bool</param> /// <param name="columnName">name of the column to sort on</param> /// <param name="sortOrder">the sort direction "ASC" or "DESC"</param> /// <returns>DataTable</returns> public static DataTable GetDirectoryTableData(string path, MDirectoryProfile directoryProfile, bool filesOnly, string columnName, string sortOrder) { if (directoryProfile == null) { throw new ArgumentNullException("directoryProfile", "directoryProfile can not be null reference (Nothing in Visual Basic)"); } DataTable mRetTable = getDataTable(); DataRow mRow = mRetTable.NewRow(); StringBuilder mStringBuilder = new StringBuilder(4096); string[] mDirs = null; char mDirectorySeparatorChar = System.IO.Path.DirectorySeparatorChar; WindowsImpersonationContext mImpersonatedUser = null; if (directoryProfile.Impersonate) { mImpersonatedUser = WebImpersonate.ImpersonateNow(directoryProfile.ImpersonateAccount, directoryProfile.ImpersonatePassword); } mRow["Name"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); // Clear the string builder if (!filesOnly) { try { mDirs = Directory.GetDirectories(path); foreach (string mDirectory in mDirs) { string mDirName = System.IO.Path.GetFileName(mDirectory); mStringBuilder = new StringBuilder(); // Clear the string builder mRow = mRetTable.NewRow(); // Create a new row // Populate the string for the new row mStringBuilder.Append(mDirName); // Populate the cell in the row mRow["Name"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); // Clear the string builder mRow["ShortFileName"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); // Clear the string builder mRow["Extension"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); // Clear the string builder // Populate the cell in the row mRow["Delete"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); // Clear the string builder mStringBuilder.Append("Folder"); // Populate the cell in the row mRow["Type"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); // Clear the string builder mStringBuilder.Append("N/A"); // Populate the cell in the row mRow["Size"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); // Clear the string builder mStringBuilder.Append(Directory.GetLastWriteTime(path + mDirectorySeparatorChar.ToString(CultureInfo.InvariantCulture) + mDirName).ToString()); // Populate the cell in the row mRow["Modified"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); mStringBuilder.Append(mDirectorySeparatorChar.ToString(CultureInfo.InvariantCulture) + mDirName + "\\"); mRow["FullName"] = mStringBuilder.ToString(); mRetTable.Rows.Add(mRow); // Add the row to the table } } catch (IOException ex) { if (mRetTable != null) { mRetTable.Dispose(); } Logger mLog = Logger.Instance(); mLog.Error(ex); throw; } } // Add all of the directories to the table try { DirectoryInfo dirInfo = new DirectoryInfo(path); FileInfo[] files = null; files = dirInfo.GetFiles(); //FileInfo mFileInfo = null; if (mRetTable == null) { } foreach (FileInfo mFileInfo in files) { mRow = mRetTable.NewRow(); string mFilename = mFileInfo.Name; string mShortFileName = mFileInfo.Name; mShortFileName = mFilename.Remove(mFilename.Length - mFileInfo.Extension.Length, mFileInfo.Extension.Length); mStringBuilder = new StringBuilder(); mStringBuilder.Append(mFilename); mRow["Name"] = mFilename.ToString(); mStringBuilder = new StringBuilder(); mStringBuilder.Append("File"); mRow["Type"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); mStringBuilder.Append(mShortFileName); mRow["shortFileName"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); string fileExtension = mFileInfo.Extension; mStringBuilder.Append(fileExtension); mRow["Extension"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); mStringBuilder.Append(mFileInfo.Length.ToFileSize()); mRow["Size"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); mStringBuilder.Append(File.GetLastWriteTime(path + mDirectorySeparatorChar.ToString() + mFileInfo.Name).ToString()); mRow["Modified"] = mStringBuilder.ToString(); mStringBuilder = new StringBuilder(); mStringBuilder.Append(mFileInfo.FullName); mRow["FullName"] = mStringBuilder.ToString(); mRetTable.Rows.Add(mRow); } } catch (IOException ex) { if (mRetTable != null) { mRetTable.Dispose(); } Logger mLog = Logger.Instance(); mLog.Error(ex); throw; } finally { if (directoryProfile.Impersonate) { // Stop impersonating the user. if ((mImpersonatedUser != null)) { mImpersonatedUser.Undo(); } } } // Return the table object as the data source SortTable mSorter = new Framework.Common.SortTable(); String mColName = columnName; mSorter.Sort(mRetTable, mColName, sortOrder); return(mRetTable); }