Wiki.Page Save() { // Get the slashes correct and trim it txtPath.Text = txtPath.Text.Replace('\\', '/').Trim(); // Ensure they start with a slash if (!txtPath.Text.StartsWith("/")) { txtPath.Text = "/" + txtPath.Text; } // Ensure its a unique name String path = txtPath.Text; string newurlpath = Wiki.Page.PathToUrlPath(path); // Are they renaming it? If so, check for dupes if (urlpath.ToLower() != newurlpath.ToLower()) { int uniqCount = 2; while (DbServices.PageExistsWithUrlpath(newurlpath)) { path = txtPath.Text + " " + uniqCount.ToString(); newurlpath = Wiki.Page.PathToUrlPath(path); uniqCount++; } } Wiki.Page page = DbServices.FindPageByUrlpath(urlpath); page.path = path; page.contents = txtRichEditor.Text.Trim(); page.author = Auth.UserName; page.Save(); return(page); }
protected void bnSave_Click(object sender, EventArgs e) { // Get the slashes correct and trim it txtPath.Text = txtPath.Text.Replace('\\', '/').Trim(); // Ensure they start with a slash if (!txtPath.Text.StartsWith("/")) { txtPath.Text = "/" + txtPath.Text; } // Ensure its a unique name String path = txtPath.Text; string urlpath = Wiki.Page.PathToUrlPath(path); int uniqCount = 2; while (DbServices.PageExistsWithUrlpath(urlpath)) { path = txtPath.Text + " " + uniqCount.ToString(); urlpath = Wiki.Page.PathToUrlPath(path); uniqCount++; } // Save it Wiki.Page page = new Wiki.Page(); page.path = path; page.contents = txtRichEditor.Text.Trim(); page.author = Auth.UserName; page.Save(); Response.Redirect("./?" + page.urlpath); }